<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `sale_refunds` (
            `id`              BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `sale_id`         BIGINT UNSIGNED NOT NULL,
            `refund_number`   VARCHAR(50) NOT NULL,
            `refund_amount`   DECIMAL(15,2) NOT NULL,
            `reason`          TEXT NOT NULL,
            `return_to_stock` TINYINT(1) NOT NULL DEFAULT 1,
            `warehouse_id`    BIGINT UNSIGNED NULL,
            `payment_id`      BIGINT UNSIGNED NULL,
            `refunded_by`     BIGINT UNSIGNED NULL,
            `refund_date`     DATE NOT NULL,
            `notes`           TEXT NULL,
            `created_at`      TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `created_by`      BIGINT UNSIGNED NULL,
            UNIQUE KEY `uq_sale_refunds_refund_number` (`refund_number`),
            INDEX `idx_sale_refunds_sale` (`sale_id`),
            INDEX `idx_sale_refunds_date` (`refund_date`),
            CONSTRAINT `fk_sale_refunds_sale` FOREIGN KEY (`sale_id`) REFERENCES `sales`(`id`) ON DELETE RESTRICT,
            CONSTRAINT `fk_sale_refunds_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_sale_refunds_payment` FOREIGN KEY (`payment_id`) REFERENCES `payments`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `sale_refunds`",
];
