<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `carnets` (
            `id`                  BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `member_id`           BIGINT UNSIGNED NOT NULL,
            `carnet_number`       VARCHAR(50) NOT NULL,
            `carnet_type`         VARCHAR(30) NOT NULL DEFAULT 'regular',
            `qr_code_data`        VARCHAR(500) NULL,
            `is_active`           TINYINT(1) NOT NULL DEFAULT 1,
            `issued_at`           TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `issued_by`           BIGINT UNSIGNED NULL,
            `deactivated_at`      TIMESTAMP NULL DEFAULT NULL,
            `deactivated_reason`  VARCHAR(200) NULL,
            `replacement_count`   INT UNSIGNED NOT NULL DEFAULT 0,
            `previous_carnet_id`  BIGINT UNSIGNED NULL,
            `print_count`         INT UNSIGNED NOT NULL DEFAULT 0,
            `last_printed_at`     TIMESTAMP NULL DEFAULT NULL,
            `last_printed_by`     BIGINT UNSIGNED 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_carnets_number` (`carnet_number`),
            INDEX `idx_carnets_member` (`member_id`),
            INDEX `idx_carnets_active` (`is_active`),
            INDEX `idx_carnets_type` (`carnet_type`),
            CONSTRAINT `fk_carnets_member` FOREIGN KEY (`member_id`) REFERENCES `members`(`id`),
            CONSTRAINT `fk_carnets_previous` FOREIGN KEY (`previous_carnet_id`) REFERENCES `carnets`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `carnets`",
];