<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `rental_contracts` (
            `id`                       BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `contract_number`          VARCHAR(50) NOT NULL,
            `entity_id`                BIGINT UNSIGNED NOT NULL,
            `facility_id`              BIGINT UNSIGNED NOT NULL,
            `activity_type`            VARCHAR(30) NOT NULL DEFAULT 'practice' COMMENT 'practice, competitive, event, training',
            `start_date`               DATE NOT NULL,
            `end_date`                 DATE NOT NULL,
            `total_units`              INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Total hours/sessions',
            `unit_rate`                DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `time_tier`                VARCHAR(5) NOT NULL DEFAULT 'AM' COMMENT 'AM, PM',
            `subtotal`                 DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `discount_percentage`      DECIMAL(5,2) NOT NULL DEFAULT 0.00 COMMENT '15% for bulk (24+ units, 2+ months)',
            `discount_amount`          DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `total_amount`             DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `deposit_percentage`       DECIMAL(5,2) NOT NULL DEFAULT 10.00,
            `deposit_amount`           DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `deposit_status`           VARCHAR(20) NOT NULL DEFAULT 'pending' COMMENT 'pending, collected, partially_refunded, refunded',
            `deposit_payment_id`       BIGINT UNSIGNED NULL,
            `technical_report_submitted` TINYINT(1) NOT NULL DEFAULT 0,
            `status`                   VARCHAR(20) NOT NULL DEFAULT 'draft' COMMENT 'draft, pending_approval, approved, active, completed, cancelled, terminated',
            `approved_by`              BIGINT UNSIGNED NULL,
            `approved_at`              TIMESTAMP NULL DEFAULT NULL,
            `terms_json`               JSON NULL COMMENT 'Additional contract terms',
            `notes`                    TEXT NULL,
            `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,
            `created_by`               BIGINT UNSIGNED NULL,
            `updated_by`               BIGINT UNSIGNED NULL,
            UNIQUE KEY `uq_rental_contracts_number` (`contract_number`),
            INDEX `idx_rc_entity` (`entity_id`),
            INDEX `idx_rc_facility` (`facility_id`),
            INDEX `idx_rc_status` (`status`),
            INDEX `idx_rc_dates` (`start_date`, `end_date`),
            CONSTRAINT `fk_rc_entity` FOREIGN KEY (`entity_id`) REFERENCES `rental_entities`(`id`) ON DELETE RESTRICT,
            CONSTRAINT `fk_rc_facility` FOREIGN KEY (`facility_id`) REFERENCES `facilities`(`id`) ON DELETE RESTRICT,
            CONSTRAINT `fk_rc_deposit_payment` FOREIGN KEY (`deposit_payment_id`) REFERENCES `payments`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `rental_contracts`",
];
