<?php

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

use Flyerimage\Core\Database\MigrationBase;

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

        // campaign_version: 'v2' (legacy) or 'v3' (new popup designer)
        $this->queries[] = "ALTER TABLE `{$table_name}` ADD COLUMN `campaign_version` VARCHAR(5) NULL DEFAULT NULL";

        // trigger_type: exit | time | scroll | click | idle — enables filtering by trigger
        $this->queries[] = "ALTER TABLE `{$table_name}` ADD COLUMN `trigger_type` VARCHAR(30) NULL DEFAULT NULL";

        $this->queries[] = "ALTER TABLE `{$table_name}` ADD INDEX `IDX_campaign_version` (`campaign_version`)";
        $this->queries[] = "ALTER TABLE `{$table_name}` ADD INDEX `IDX_trigger_type` (`trigger_type`)";
    }

    public function down() {
        $table      = \Flyerimage\App\Constants\ITables::$FLYER_IMAGES;
        $table_name = $this->table_name($table);
        $this->queries[] = "ALTER TABLE `{$table_name}` DROP INDEX `IDX_trigger_type`";
        $this->queries[] = "ALTER TABLE `{$table_name}` DROP INDEX `IDX_campaign_version`";
        $this->queries[] = "ALTER TABLE `{$table_name}` DROP COLUMN `trigger_type`";
        $this->queries[] = "ALTER TABLE `{$table_name}` DROP COLUMN `campaign_version`";
    }
};
