<?php
declare(strict_types=1);

return [
    'up' => "
CREATE TABLE rental_invoices (
    id                  bigint unsigned  NOT NULL AUTO_INCREMENT,
    invoice_number      varchar(50)      NOT NULL,
    contract_id         bigint unsigned  NOT NULL,
    entity_id           bigint unsigned  NOT NULL,
    period_start        date             NOT NULL,
    period_end          date             NOT NULL,
    due_date            date             NOT NULL,
    base_amount         decimal(15,2)    NOT NULL DEFAULT 0.00,
    utilities_amount    decimal(15,2)    NOT NULL DEFAULT 0.00,
    vat_amount          decimal(15,2)    NOT NULL DEFAULT 0.00,
    late_fee_amount     decimal(15,2)    NOT NULL DEFAULT 0.00,
    total_amount        decimal(15,2)    NOT NULL DEFAULT 0.00,
    status              varchar(20)      NOT NULL DEFAULT 'unpaid',
    paid_at             timestamp        NULL     DEFAULT NULL,
    payment_id          bigint unsigned  NULL     DEFAULT NULL,
    notes               text             NULL,
    journal_entry_id    bigint unsigned  NULL     DEFAULT 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,
    PRIMARY KEY (id),
    UNIQUE KEY uq_rental_invoices_number (invoice_number),
    KEY idx_rental_invoices_contract (contract_id),
    KEY idx_rental_invoices_entity (entity_id),
    KEY idx_rental_invoices_status (status),
    KEY idx_rental_invoices_due_date (due_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
",
    'down' => "DROP TABLE IF EXISTS rental_invoices;",
];
