<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `transfer_requests` (
            `id`                         BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `source_member_id`           BIGINT UNSIGNED NOT NULL,
            `target_member_id`           BIGINT UNSIGNED NULL,
            `transfer_type`              VARCHAR(50) NOT NULL,
            `child_id`                   BIGINT UNSIGNED NULL,
            `spouse_id`                  BIGINT UNSIGNED NULL,
            `source_membership_number`   VARCHAR(20) NULL,
            `new_membership_number`      VARCHAR(20) NULL,
            `new_membership_value`       DECIMAL(15,2) NULL,
            `years_since_acquisition`    INT UNSIGNED NULL,
            `qualification_code`         VARCHAR(20) NULL,
            `fee_percentage`             DECIMAL(5,2) NULL,
            `separation_fee`             DECIMAL(15,2) NULL,
            `form_fee`                   DECIMAL(15,2) NULL,
            `annual_subscription_fee`    DECIMAL(15,2) NULL,
            `total_fee`                  DECIMAL(15,2) NULL,
            `archive_snapshot_id`        BIGINT UNSIGNED NULL,
            `workflow_instance_id`       BIGINT UNSIGNED NULL,
            `board_decision_notes`       TEXT NULL,
            `approved_by`                BIGINT UNSIGNED NULL,
            `approved_at`                TIMESTAMP NULL DEFAULT NULL,
            `completed_at`               TIMESTAMP NULL DEFAULT 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_transfers_source` (`source_member_id`),
            INDEX `idx_transfers_target` (`target_member_id`),
            INDEX `idx_transfers_type` (`transfer_type`),
            INDEX `idx_transfers_status` (`status`),
            INDEX `idx_transfers_child` (`child_id`),
            INDEX `idx_transfers_spouse` (`spouse_id`),
            CONSTRAINT `fk_transfers_source` FOREIGN KEY (`source_member_id`) REFERENCES `members`(`id`),
            CONSTRAINT `fk_transfers_target` FOREIGN KEY (`target_member_id`) REFERENCES `members`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_transfers_child` FOREIGN KEY (`child_id`) REFERENCES `children`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_transfers_spouse` FOREIGN KEY (`spouse_id`) REFERENCES `spouses`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_transfers_snapshot` FOREIGN KEY (`archive_snapshot_id`) REFERENCES `archive_snapshots`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_transfers_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 `transfer_requests`",
];