<?php

use Openguru\OpenCartFramework\Migrations\Migration;

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

        $sql = <<<SQL
            CREATE TABLE IF NOT EXISTS `{$tableName}` (
                `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
                `oc_order_id` INT(11) UNSIGNED NOT NULL,
                `oc_store_id` INT(11) UNSIGNED NOT NULL,
                `telecart_customer_id` INT(11) UNSIGNED DEFAULT NULL,
                `meta_data` JSON 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_oc_order_id` (`oc_order_id`),
                KEY `idx_oc_store_id` (`oc_store_id`),
                KEY `idx_telecart_customer_id` (`telecart_customer_id`)
            ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB;
SQL;

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

