<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `subscriptions` (
            `id`               BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `member_id`        BIGINT UNSIGNED NOT NULL,
            `financial_year`   VARCHAR(10) NOT NULL,
            `person_type`      VARCHAR(50) NOT NULL,
            `person_id`        BIGINT UNSIGNED NULL,
            `person_name`      VARCHAR(200) NULL,
            `base_amount`      DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `development_fee`  DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `discount_amount`  DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `total_amount`     DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `paid_amount`      DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `fine_amount`      DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `status`           VARCHAR(50) NOT NULL DEFAULT 'pending',
            `paid_at`          TIMESTAMP NULL DEFAULT NULL,
            `payment_id`       BIGINT UNSIGNED NULL,
            `exempted_by`      BIGINT UNSIGNED NULL,
            `exemption_reason` 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,
            `updated_by`       BIGINT UNSIGNED NULL,
            INDEX `idx_subscriptions_member` (`member_id`),
            INDEX `idx_subscriptions_year` (`financial_year`),
            INDEX `idx_subscriptions_status` (`status`),
            INDEX `idx_subscriptions_person` (`person_type`, `person_id`),
            CONSTRAINT `fk_subscriptions_member` FOREIGN KEY (`member_id`) REFERENCES `members`(`id`),
            CONSTRAINT `fk_subscriptions_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 `subscriptions`",
];