<?php
declare(strict_types=1);

return [
    'up' => "CREATE TABLE IF NOT EXISTS `academy_revenue_records` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `academy_id` BIGINT UNSIGNED NOT NULL,
    `contract_id` BIGINT UNSIGNED NOT NULL,
    `period_month` VARCHAR(7) NOT NULL COMMENT 'YYYY-MM',
    `subscription_revenue` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `registration_revenue` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `other_revenue` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `total_revenue` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `enrolled_count` INT UNSIGNED NOT NULL DEFAULT 0,
    `active_players_count` INT UNSIGNED NOT NULL DEFAULT 0,
    `is_finalized` TINYINT(1) NOT NULL DEFAULT 0,
    `calculated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY `uq_arr_academy_contract_month` (`academy_id`, `contract_id`, `period_month`),
    INDEX `idx_arr_contract` (`contract_id`),
    CONSTRAINT `fk_arr_academy` FOREIGN KEY (`academy_id`) REFERENCES `academies`(`id`) ON DELETE RESTRICT,
    CONSTRAINT `fk_arr_contract` FOREIGN KEY (`contract_id`) REFERENCES `academy_contracts`(`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci",
    'down' => "DROP TABLE IF EXISTS `academy_revenue_records`",
];
