<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `documents` (
            `id`                   BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `member_id`            BIGINT UNSIGNED NOT NULL,
            `document_type`        VARCHAR(50) NOT NULL,
            `original_filename`    VARCHAR(500) NOT NULL,
            `stored_filename`      VARCHAR(500) NOT NULL,
            `file_path`            VARCHAR(1000) NOT NULL,
            `file_size`            INT UNSIGNED NOT NULL DEFAULT 0,
            `mime_type`            VARCHAR(100) NOT NULL,
            `related_entity_type`  VARCHAR(100) NULL,
            `related_entity_id`    BIGINT UNSIGNED NULL,
            `description`          TEXT NULL,
            `uploaded_by`          BIGINT UNSIGNED NULL,
            `uploaded_at`          TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `is_archived`          TINYINT(1) NOT NULL DEFAULT 0,
            `archived_at`          TIMESTAMP NULL DEFAULT NULL,
            `archived_by`          BIGINT UNSIGNED NULL,
            `created_at`           TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`           TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            INDEX `idx_documents_member` (`member_id`),
            INDEX `idx_documents_type` (`document_type`),
            INDEX `idx_documents_related` (`related_entity_type`, `related_entity_id`),
            INDEX `idx_documents_archived` (`is_archived`),
            CONSTRAINT `fk_documents_member` FOREIGN KEY (`member_id`) REFERENCES `members`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `documents`",
];