<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `installment_plans` (
            `id`                   BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `member_id`            BIGINT UNSIGNED NOT NULL,
            `related_entity_type`  VARCHAR(100) NULL,
            `related_entity_id`    BIGINT UNSIGNED NULL,
            `total_amount`         DECIMAL(15,2) NOT NULL,
            `down_payment`         DECIMAL(15,2) NOT NULL,
            `remaining_balance`    DECIMAL(15,2) NOT NULL,
            `interest_rate`        DECIMAL(5,2) NOT NULL DEFAULT 22.00,
            `total_interest`       DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `total_with_interest`  DECIMAL(15,2) NOT NULL,
            `number_of_months`     INT UNSIGNED NOT NULL,
            `monthly_payment`      DECIMAL(15,2) NOT NULL,
            `start_date`           DATE NOT NULL,
            `down_payment_receipt` VARCHAR(50) NULL,
            `cash_settlement_date` DATE NULL,
            `is_cash_settled`      TINYINT(1) NOT NULL DEFAULT 0,
            `status`               VARCHAR(50) NOT NULL DEFAULT 'active',
            `notes`                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_installment_plans_member` (`member_id`),
            INDEX `idx_installment_plans_status` (`status`),
            CONSTRAINT `fk_installment_plans_member` FOREIGN KEY (`member_id`) REFERENCES `members`(`id`),
            CONSTRAINT `chk_installment_down` CHECK (`down_payment` >= 0),
            CONSTRAINT `chk_installment_total` CHECK (`total_amount` > 0)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `installment_plans`",
];