<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `activity_subscriptions` (
            `id`                  BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `player_id`           BIGINT UNSIGNED NOT NULL,
            `enrollment_id`       BIGINT UNSIGNED NULL,
            `discipline_id`       BIGINT UNSIGNED NULL,
            `subscription_month`  VARCHAR(7) NOT NULL COMMENT 'YYYY-MM format',
            `player_type`         VARCHAR(20) NOT NULL COMMENT 'member, non_member',
            `base_rate`           DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `is_half_month`       TINYINT(1) NOT NULL DEFAULT 0,
            `applied_rate`        DECIMAL(15,2) NOT NULL DEFAULT 0.00 COMMENT 'Half of base_rate if is_half_month',
            `discount`            DECIMAL(15,2) NOT NULL DEFAULT 0.00 COMMENT 'Super admin only can apply discount',
            `total_amount`        DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `payment_id`          BIGINT UNSIGNED NULL,
            `status`              VARCHAR(20) NOT NULL DEFAULT 'pending' COMMENT 'pending, paid, overdue, exempted, revoked',
            `due_date`            DATE NULL COMMENT '7th of subscription month',
            `paid_at`             TIMESTAMP NULL DEFAULT NULL,
            `revoked_at`          TIMESTAMP NULL DEFAULT NULL,
            `exempted_by`         BIGINT UNSIGNED NULL,
            `exemption_reason`    VARCHAR(500) NULL,
            `notes`               TEXT NULL,
            `created_at`          TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`          TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            `is_archived`         TINYINT(1) NOT NULL DEFAULT 0,
            `archived_at`         TIMESTAMP NULL DEFAULT NULL,
            `archived_by`         BIGINT UNSIGNED NULL,
            `created_by`          BIGINT UNSIGNED NULL,
            INDEX `idx_as_player` (`player_id`),
            INDEX `idx_as_enrollment` (`enrollment_id`),
            INDEX `idx_as_discipline` (`discipline_id`),
            INDEX `idx_as_month` (`subscription_month`),
            INDEX `idx_as_status` (`status`),
            INDEX `idx_as_due_date` (`due_date`),
            INDEX `idx_as_player_month` (`player_id`, `subscription_month`),
            CONSTRAINT `fk_as_player` FOREIGN KEY (`player_id`) REFERENCES `players`(`id`) ON DELETE CASCADE,
            CONSTRAINT `fk_as_enrollment` FOREIGN KEY (`enrollment_id`) REFERENCES `academy_enrollments`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_as_discipline` FOREIGN KEY (`discipline_id`) REFERENCES `sport_disciplines`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_as_payment` FOREIGN KEY (`payment_id`) REFERENCES `payments`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `activity_subscriptions`",
];
