<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `waiver_requests` (
            `id`                         BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `source_member_id`           BIGINT UNSIGNED NOT NULL,
            `target_member_id`           BIGINT UNSIGNED NULL,
            `membership_number`          VARCHAR(20) NOT NULL,
            `membership_value_at_waiver` DECIMAL(15,2) NOT NULL,
            `waiver_fee_percentage`      DECIMAL(5,2) NOT NULL DEFAULT 30.00,
            `waiver_fee_amount`          DECIMAL(15,2) NOT NULL,
            `original_dependent_count`   INT UNSIGNED NOT NULL DEFAULT 0,
            `new_dependent_count`        INT UNSIGNED NULL,
            `board_approval_required`    TINYINT(1) NOT NULL DEFAULT 1,
            `board_decision_reference`   VARCHAR(100) NULL,
            `approved_by`                BIGINT UNSIGNED NULL,
            `approved_at`                TIMESTAMP NULL DEFAULT NULL,
            `annual_renewal_paid`        TINYINT(1) NOT NULL DEFAULT 0,
            `archive_snapshot_id`        BIGINT UNSIGNED NULL,
            `workflow_instance_id`       BIGINT UNSIGNED NULL,
            `status`                     VARCHAR(50) NOT NULL DEFAULT 'requested',
            `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,
            `updated_by`                 BIGINT UNSIGNED NULL,
            INDEX `idx_waiver_source` (`source_member_id`),
            INDEX `idx_waiver_target` (`target_member_id`),
            INDEX `idx_waiver_number` (`membership_number`),
            INDEX `idx_waiver_status` (`status`),
            CONSTRAINT `fk_waiver_source` FOREIGN KEY (`source_member_id`) REFERENCES `members`(`id`),
            CONSTRAINT `fk_waiver_target` FOREIGN KEY (`target_member_id`) REFERENCES `members`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_waiver_snapshot` FOREIGN KEY (`archive_snapshot_id`) REFERENCES `archive_snapshots`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_waiver_workflow` FOREIGN KEY (`workflow_instance_id`) REFERENCES `workflow_instances`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `waiver_requests`",
];