<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `payment_requests` (
            `id`                    BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `request_number`        VARCHAR(50) NOT NULL UNIQUE,
            `member_id`             BIGINT UNSIGNED NOT NULL,

            `payment_type`          VARCHAR(50) NOT NULL,
            `amount`                DECIMAL(15,2) NOT NULL,
            `currency`              VARCHAR(3) NOT NULL DEFAULT 'EGP',
            `description_ar`        TEXT NULL,

            `related_entity_type`   VARCHAR(100) NULL,
            `related_entity_id`     BIGINT UNSIGNED NULL,

            `status`                VARCHAR(30) NOT NULL DEFAULT 'pending',

            `payment_id`            BIGINT UNSIGNED NULL,
            `receipt_number`        VARCHAR(50) NULL,

            `requested_by`          BIGINT UNSIGNED NOT NULL,
            `processed_by`          BIGINT UNSIGNED NULL,
            `processed_at`          TIMESTAMP NULL DEFAULT NULL,

            `branch_id`             BIGINT UNSIGNED NULL,
            `notes`                 TEXT 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,

            INDEX `idx_pr_status` (`status`),
            INDEX `idx_pr_member` (`member_id`),
            INDEX `idx_pr_branch` (`branch_id`),
            INDEX `idx_pr_requested_by` (`requested_by`),
            INDEX `idx_pr_payment_type` (`payment_type`),
            INDEX `idx_pr_related` (`related_entity_type`, `related_entity_id`),
            CONSTRAINT `fk_pr_member` FOREIGN KEY (`member_id`) REFERENCES `members`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `payment_requests`",
];
