<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `fines` (
            `id`                  BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `member_id`           BIGINT UNSIGNED NOT NULL,
            `violation_id`        BIGINT UNSIGNED NULL,
            `fine_type`           VARCHAR(50) NOT NULL DEFAULT 'violation_fine',
            `amount`              DECIMAL(15,2) NOT NULL,
            `penalty_type`        VARCHAR(50) NOT NULL DEFAULT 'fine',
            `suspension_from`     DATE NULL,
            `suspension_to`       DATE NULL,
            `appeal_submitted`    TINYINT(1) NOT NULL DEFAULT 0,
            `appeal_date`         DATE NULL,
            `appeal_notes`        TEXT NULL,
            `appeal_decision`     VARCHAR(50) NULL,
            `appeal_decided_by`   BIGINT UNSIGNED NULL,
            `appeal_decided_at`   TIMESTAMP NULL DEFAULT NULL,
            `status`              VARCHAR(50) NOT NULL DEFAULT 'imposed',
            `paid_amount`         DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `payment_id`          BIGINT UNSIGNED NULL,
            `paid_at`             TIMESTAMP NULL DEFAULT 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,
            INDEX `idx_fines_member` (`member_id`),
            INDEX `idx_fines_violation` (`violation_id`),
            INDEX `idx_fines_type` (`fine_type`),
            INDEX `idx_fines_penalty` (`penalty_type`),
            INDEX `idx_fines_status` (`status`),
            INDEX `idx_fines_suspension` (`suspension_from`, `suspension_to`),
            CONSTRAINT `fk_fines_member` FOREIGN KEY (`member_id`) REFERENCES `members`(`id`),
            CONSTRAINT `fk_fines_violation` FOREIGN KEY (`violation_id`) REFERENCES `violations`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_fines_payment` FOREIGN KEY (`payment_id`) REFERENCES `payments`(`id`) ON DELETE SET NULL,
            CONSTRAINT `chk_fines_amount` CHECK (`amount` >= 0)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `fines`",
];