<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `installment_schedule` (
            `id`                  BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `installment_plan_id` BIGINT UNSIGNED NOT NULL,
            `installment_number`  INT UNSIGNED NOT NULL,
            `due_date`            DATE NOT NULL,
            `amount`              DECIMAL(15,2) NOT NULL,
            `principal`           DECIMAL(15,2) NOT NULL,
            `interest`            DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `remaining_after`     DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `paid_amount`         DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `payment_id`          BIGINT UNSIGNED NULL,
            `status`              VARCHAR(30) NOT NULL DEFAULT 'pending',
            `paid_at`             TIMESTAMP NULL DEFAULT NULL,
            `created_at`          TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`          TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            INDEX `idx_installment_sched_plan` (`installment_plan_id`),
            INDEX `idx_installment_sched_due` (`due_date`),
            INDEX `idx_installment_sched_status` (`status`),
            CONSTRAINT `fk_installment_sched_plan` FOREIGN KEY (`installment_plan_id`) REFERENCES `installment_plans`(`id`) ON DELETE CASCADE,
            CONSTRAINT `fk_installment_sched_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 `installment_schedule`",
];