<?php
/**
 * Created by PhpStorm.
 * User: Pritom
 * Date: 5/16/2024
 * Time: 12:00 AM
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

use Flyerimage\Core\Database\MigrationBase;

return new class extends MigrationBase  {
    public function up() {
        $this->table = \Flyerimage\App\Constants\ITables::$FLYER_IMAGES;
        $this->columns = [
            "`id` bigint NOT NULL AUTO_INCREMENT",
            "`status` varchar(30) NOT NULL DEFAULT 'active'",
            "`title` varchar(250) NOT NULL",
            "`description` varchar(400) DEFAULT NULL",
            "`start_date` DATE NULL DEFAULT NULL",
            "`start_time` int(5) NULL DEFAULT NULL",
            "`end_date` DATE NULL DEFAULT NULL",
            "`end_time` int(5) NULL DEFAULT NULL",
            "`show_for_all_pages` TINYINT(1) NULL DEFAULT NULL",
            "`flyer_configs` TEXT NULL DEFAULT NULL",
            "`created_at` DATETIME NOT NULL",
            "`created_by` bigint NOT NULL",
            "`updated_at` DATETIME NOT NULL",
            "`updated_by` bigint NOT NULL",
            "PRIMARY KEY (`id`)",
        ];

        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_status` (`status`)";
        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_start_date` (`start_date`)";
        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_end_date` (`end_date`)";
        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_show_for_all_pages` (`show_for_all_pages`)";
    }

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