<?php

use Openguru\OpenCartFramework\Migrations\Migration;

return new class extends Migration {
    public function up(): void
    {
        $tableName = 'telecart_customers';

        $sql = <<<SQL
            CREATE TABLE IF NOT EXISTS `{$tableName}` (
                `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
                `telegram_user_id` BIGINT(20) UNSIGNED NOT NULL,
                `oc_customer_id` INT(11) UNSIGNED DEFAULT NULL,
                `username` VARCHAR(255) DEFAULT NULL,
                `first_name` VARCHAR(255) DEFAULT NULL,
                `last_name` VARCHAR(255) DEFAULT NULL,
                `language_code` VARCHAR(10) DEFAULT NULL,
                `is_premium` TINYINT(1) UNSIGNED DEFAULT 0,
                `allows_write_to_pm` TINYINT(1) UNSIGNED DEFAULT 0,
                `photo_url` VARCHAR(512) DEFAULT NULL,
                `last_seen_at` DATETIME DEFAULT NULL,
                `referral` VARCHAR(255) DEFAULT NULL,
                `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
                `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                PRIMARY KEY (`id`),
                UNIQUE KEY `unique_telegram_user_id` (`telegram_user_id`),
                KEY `idx_oc_customer_id` (`oc_customer_id`),
                KEY `idx_last_seen_at` (`last_seen_at`)
            ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB;
SQL;

        $this->database->statement($sql);
    }
};

