<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `divorce_cases` (
            `id`                            BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `member_id`                     BIGINT UNSIGNED NOT NULL,
            `spouse_id`                     BIGINT UNSIGNED NOT NULL,
            `divorce_date`                  DATE NOT NULL,
            `divorce_case_type`             VARCHAR(50) NOT NULL,
            `request_date`                  DATE NOT NULL,
            `membership_acquisition_date`   DATE NULL,
            `years_of_membership`           INT UNSIGNED NULL,
            `has_children_on_membership`    TINYINT(1) NOT NULL DEFAULT 0,
            `fee_percentage`                DECIMAL(5,2) NULL,
            `fee_amount`                    DECIMAL(15,2) NULL,
            `spouse_new_member_id`          BIGINT UNSIGNED NULL,
            `spouse_new_membership_number`  VARCHAR(20) NULL,
            `children_assignment_json`      JSON NULL,
            `archive_snapshot_id`           BIGINT UNSIGNED NULL,
            `workflow_instance_id`          BIGINT UNSIGNED NULL,
            `status`                        VARCHAR(50) NOT NULL DEFAULT 'submitted',
            `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_divorce_member` (`member_id`),
            INDEX `idx_divorce_spouse` (`spouse_id`),
            INDEX `idx_divorce_status` (`status`),
            INDEX `idx_divorce_date` (`divorce_date`),
            CONSTRAINT `fk_divorce_member` FOREIGN KEY (`member_id`) REFERENCES `members`(`id`),
            CONSTRAINT `fk_divorce_spouse` FOREIGN KEY (`spouse_id`) REFERENCES `spouses`(`id`),
            CONSTRAINT `fk_divorce_new_member` FOREIGN KEY (`spouse_new_member_id`) REFERENCES `members`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_divorce_snapshot` FOREIGN KEY (`archive_snapshot_id`) REFERENCES `archive_snapshots`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_divorce_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 `divorce_cases`",
];