<?php
declare(strict_types=1);

return [
    'up' => "
CREATE TABLE IF NOT EXISTS cross_entity_settlements (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    settlement_number VARCHAR(50) NOT NULL,
    settlement_date DATE NOT NULL,
    from_entity_type ENUM('customer','supplier','bank','safe') NOT NULL,
    from_entity_id INT UNSIGNED NOT NULL,
    from_entity_name VARCHAR(255) NOT NULL,
    to_entity_type ENUM('customer','supplier','bank','safe') NOT NULL,
    to_entity_id INT UNSIGNED NOT NULL,
    to_entity_name VARCHAR(255) NOT NULL,
    amount DECIMAL(15,2) NOT NULL,
    purpose ENUM('payment','advance','adjustment','transfer') NOT NULL DEFAULT 'payment',
    description VARCHAR(500) NULL,
    journal_entry_id INT UNSIGNED NULL,
    status ENUM('draft','approved','posted','cancelled') NOT NULL DEFAULT 'draft',
    approved_by INT UNSIGNED NULL,
    approved_at DATETIME NULL,
    created_by INT UNSIGNED NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NULL ON UPDATE CURRENT_TIMESTAMP,
    KEY idx_date (settlement_date),
    KEY idx_from (from_entity_type, from_entity_id),
    KEY idx_to (to_entity_type, to_entity_id),
    KEY idx_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci",
    'down' => "DROP TABLE IF EXISTS cross_entity_settlements",
];
