<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `receipts` (
            `id`                      BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `receipt_number`          VARCHAR(50) NOT NULL,
            `member_id`               BIGINT UNSIGNED NOT NULL,
            `payment_id`              BIGINT UNSIGNED NULL,
            `receipt_type`            VARCHAR(30) NOT NULL DEFAULT 'payment',
            `amount`                  DECIMAL(15,2) NOT NULL,
            `amount_in_words_ar`      TEXT NULL,
            `description_ar`          TEXT NULL,
            `issued_by_employee_id`   BIGINT UNSIGNED NULL,
            `issued_at`               TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `is_voided`               TINYINT(1) NOT NULL DEFAULT 0,
            `voided_at`               TIMESTAMP NULL DEFAULT NULL,
            `voided_by`               BIGINT UNSIGNED NULL,
            `void_reason`             TEXT 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,
            UNIQUE KEY `uq_receipts_number` (`receipt_number`),
            INDEX `idx_receipts_member` (`member_id`),
            INDEX `idx_receipts_payment` (`payment_id`),
            INDEX `idx_receipts_type` (`receipt_type`),
            INDEX `idx_receipts_voided` (`is_voided`),
            INDEX `idx_receipts_date` (`issued_at`),
            CONSTRAINT `fk_receipts_member` FOREIGN KEY (`member_id`) REFERENCES `members`(`id`),
            CONSTRAINT `fk_receipts_payment` FOREIGN KEY (`payment_id`) REFERENCES `payments`(`id`) ON DELETE SET NULL,
            CONSTRAINT `chk_receipts_amount` CHECK (`amount` >= 0)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `receipts`",
];