<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `form_submissions` (
            `id`                       BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `form_schema_id`           BIGINT UNSIGNED NOT NULL,
            `schema_version`           INT UNSIGNED NOT NULL DEFAULT 1,
            `form_number`              VARCHAR(50) NOT NULL,
            `submitted_data_json`      JSON NOT NULL,
            `status`                   VARCHAR(50) NOT NULL DEFAULT 'draft',
            `submitted_by_employee_id` BIGINT UNSIGNED NULL,
            `member_id`                BIGINT UNSIGNED NULL,
            `expires_at`               TIMESTAMP NULL DEFAULT NULL,
            `fee_receipt_number`       VARCHAR(50) NULL,
            `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,
            UNIQUE KEY `uq_form_submissions_number` (`form_number`),
            INDEX `idx_form_submissions_schema` (`form_schema_id`),
            INDEX `idx_form_submissions_status` (`status`),
            INDEX `idx_form_submissions_member` (`member_id`),
            INDEX `idx_form_submissions_expires` (`expires_at`),
            CONSTRAINT `fk_form_submissions_schema` FOREIGN KEY (`form_schema_id`) REFERENCES `form_schemas`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `form_submissions`",
];