<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `scheduled_reports` (
            `id`                   BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `report_definition_id` BIGINT UNSIGNED NOT NULL,
            `name_ar`              VARCHAR(200) NOT NULL,
            `schedule_type`        VARCHAR(30) NOT NULL DEFAULT 'monthly',
            `schedule_config_json` JSON NULL,
            `filters_json`         JSON NULL,
            `format`               VARCHAR(20) NOT NULL DEFAULT 'pdf',
            `last_generated_at`    TIMESTAMP NULL DEFAULT NULL,
            `next_run_at`          TIMESTAMP NULL DEFAULT NULL,
            `is_active`            TINYINT(1) NOT NULL DEFAULT 1,
            `created_at`           TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`           TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            `created_by`           BIGINT UNSIGNED NULL,
            `updated_by`           BIGINT UNSIGNED NULL,
            INDEX `idx_sched_reports_def` (`report_definition_id`),
            INDEX `idx_sched_reports_next` (`next_run_at`),
            INDEX `idx_sched_reports_active` (`is_active`),
            CONSTRAINT `fk_sched_reports_def` FOREIGN KEY (`report_definition_id`) REFERENCES `report_definitions`(`id`) ON DELETE CASCADE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `scheduled_reports`",
];