<?php

if ( ! defined( 'ABSPATH' ) ) exit;

use Flyerimage\Core\Database\MigrationBase;

return new class extends MigrationBase {
    public function up() {
        $table_name = $this->table_name(\Flyerimage\App\Constants\ITables::$FLYER_IMAGE_SUBMISSIONS);

        $this->queries[] = "CREATE TABLE IF NOT EXISTS `{$table_name}` (
            `id` INT NOT NULL AUTO_INCREMENT,
            `flyer_image_id` INT NOT NULL,
            `submitted_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `page_url` VARCHAR(500) DEFAULT NULL,
            `fields` LONGTEXT DEFAULT NULL,
            PRIMARY KEY (`id`),
            INDEX `IDX_flyer_image_id` (`flyer_image_id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
    }

    public function down() {
        $table_name = $this->table_name(\Flyerimage\App\Constants\ITables::$FLYER_IMAGE_SUBMISSIONS);
        $this->queries[] = "DROP TABLE IF EXISTS `{$table_name}`";
    }
};
