<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE `sa_subscriptions` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `subscription_number` VARCHAR(50) NOT NULL,
            `player_id` BIGINT UNSIGNED NOT NULL,
            `group_id` BIGINT UNSIGNED NOT NULL,
            `period_start` DATE NOT NULL,
            `period_end` DATE NOT NULL,
            `amount` DECIMAL(10,2) NOT NULL,
            `discount_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
            `final_amount` DECIMAL(10,2) NOT NULL,
            `payment_status` VARCHAR(20) NOT NULL DEFAULT 'unpaid' COMMENT 'unpaid, paid, partial, exempt, overdue',
            `paid_at` TIMESTAMP NULL,
            `paid_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
            `payment_reference` VARCHAR(100) NULL,
            `exemption_reason` TEXT NULL,
            `exempted_by` BIGINT UNSIGNED NULL,
            `notes` TEXT NULL,
            `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,
            UNIQUE KEY `uq_sa_sub_number` (`subscription_number`),
            INDEX `idx_sa_sub_player` (`player_id`),
            INDEX `idx_sa_sub_group` (`group_id`),
            INDEX `idx_sa_sub_period` (`period_start`, `period_end`),
            INDEX `idx_sa_sub_status` (`payment_status`),
            CONSTRAINT `fk_sa_sub_player` FOREIGN KEY (`player_id`) REFERENCES `sa_players`(`id`) ON DELETE RESTRICT,
            CONSTRAINT `fk_sa_sub_group` FOREIGN KEY (`group_id`) REFERENCES `sa_groups`(`id`) ON DELETE RESTRICT
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `sa_subscriptions`",
];
