<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `death_cases` (
            `id`                         BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `member_id`                  BIGINT UNSIGNED NOT NULL,
            `deceased_type`              VARCHAR(30) NOT NULL,
            `death_date`                 DATE NOT NULL,
            `death_certificate_number`   VARCHAR(100) NULL,
            `death_certificate_path`     VARCHAR(500) NULL,
            `spouse_id`                  BIGINT UNSIGNED NULL,
            `child_id`                   BIGINT UNSIGNED NULL,
            `transferred_to_member_id`   BIGINT UNSIGNED NULL,
            `same_membership_number`     TINYINT(1) NOT NULL DEFAULT 0,
            `fee_amount`                 DECIMAL(15,2) NULL,
            `archive_snapshot_id`        BIGINT UNSIGNED NULL,
            `workflow_instance_id`       BIGINT UNSIGNED NULL,
            `status`                     VARCHAR(50) NOT NULL DEFAULT 'recorded',
            `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_death_member` (`member_id`),
            INDEX `idx_death_status` (`status`),
            INDEX `idx_death_date` (`death_date`),
            CONSTRAINT `fk_death_member` FOREIGN KEY (`member_id`) REFERENCES `members`(`id`),
            CONSTRAINT `fk_death_spouse` FOREIGN KEY (`spouse_id`) REFERENCES `spouses`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_death_child` FOREIGN KEY (`child_id`) REFERENCES `children`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_death_transferred` FOREIGN KEY (`transferred_to_member_id`) REFERENCES `members`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_death_snapshot` FOREIGN KEY (`archive_snapshot_id`) REFERENCES `archive_snapshots`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_death_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 `death_cases`",
];