<?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_REPORT_FLYER_OPEN;
        $this->columns = [
            "`id` BIGINT(20) NOT NULL AUTO_INCREMENT",
            "`flyer_image_id` BIGINT(20) NOT NULL",
            "`flyer_image_screen_id` BIGINT(20) NOT NULL",
            "`action` VARCHAR(30) NOT NULL",
            "`report_date` DATE NOT NULL",
            "`report_hour` INT(5) NOT NULL",
            "`report_month` DATE NOT NULL",
            "`report_year` DATE NOT NULL",
            "`display_time` INT(11) NOT NULL",
            "`time_zone` VARCHAR(50) NOT NULL",
            "`session_id` VARCHAR(50) NOT NULL",
            "`ip_address` VARCHAR(50) NOT NULL",
            "`country_name` VARCHAR(150) NOT NULL",
            "`device_type` VARCHAR(50) NOT NULL",
            "`os_name` VARCHAR(50) NOT NULL",
            "`browser_name` VARCHAR(50) NOT NULL",
            "`page_url` TEXT NULL",
            "`page_title` TEXT NULL",
            "PRIMARY KEY (`id`)",
        ];
        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_flyer_image_id` (`flyer_image_id`)";
        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_flyer_image_screen_id` (`flyer_image_screen_id`)";
        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_action` (`action`)";
        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_report_date` (`report_date`)";
        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_report_hour` (`report_hour`)";
        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_report_month` (`report_month`)";
        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_report_year` (`report_year`)";
        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_country_name` (`country_name`)";
        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_device_type` (`device_type`)";
        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_os_name` (`os_name`)";
        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_browser_name` (`browser_name`)";
        $this->queries[] = "ALTER TABLE `{$this->table_name($this->table)}` ADD INDEX `IDX_session_id` (`session_id`)";
    }

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