<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `payments` (
            `id`                      BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `member_id`               BIGINT UNSIGNED NOT NULL,
            `receipt_id`              BIGINT UNSIGNED NULL,
            `payment_type`            VARCHAR(50) NOT NULL,
            `amount`                  DECIMAL(15,2) NOT NULL,
            `currency`                VARCHAR(3) NOT NULL DEFAULT 'EGP',
            `payment_method`          VARCHAR(30) NOT NULL DEFAULT 'cash',
            `check_number`            VARCHAR(50) NULL,
            `check_bank`              VARCHAR(200) NULL,
            `check_date`              DATE NULL,
            `check_status`            VARCHAR(30) NULL,
            `visa_reference`          VARCHAR(100) NULL,
            `transfer_reference`      VARCHAR(100) NULL,
            `transfer_bank`           VARCHAR(200) NULL,
            `related_entity_type`     VARCHAR(100) NULL,
            `related_entity_id`       BIGINT UNSIGNED NULL,
            `notes`                   TEXT NULL,
            `payment_date`            DATE NOT NULL,
            `received_by_employee_id` BIGINT UNSIGNED NULL,
            `is_voided`               TINYINT(1) NOT NULL DEFAULT 0,
            `voided_at`               TIMESTAMP NULL DEFAULT NULL,
            `voided_by`               BIGINT UNSIGNED NULL,
            `void_reason`             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_payments_member` (`member_id`),
            INDEX `idx_payments_receipt` (`receipt_id`),
            INDEX `idx_payments_type` (`payment_type`),
            INDEX `idx_payments_method` (`payment_method`),
            INDEX `idx_payments_date` (`payment_date`),
            INDEX `idx_payments_voided` (`is_voided`),
            INDEX `idx_payments_related` (`related_entity_type`, `related_entity_id`),
            INDEX `idx_payments_check_status` (`check_status`),
            CONSTRAINT `fk_payments_member` FOREIGN KEY (`member_id`) REFERENCES `members`(`id`),
            CONSTRAINT `chk_payments_amount` CHECK (`amount` >= 0)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `payments`",
];