<?php
declare(strict_types=1);

return [
    'up' => "
CREATE TABLE IF NOT EXISTS customer_transactions (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    member_id INT UNSIGNED NOT NULL,
    transaction_date DATE NOT NULL,
    document_type ENUM('sale','refund','payment','fine','subscription','installment','opening_balance','adjustment') NOT NULL,
    document_id INT UNSIGNED NULL,
    document_number VARCHAR(50) NULL,
    description VARCHAR(500) NOT NULL,
    debit DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    credit DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    balance DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    branch_id INT UNSIGNED NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    KEY idx_member (member_id),
    KEY idx_date (transaction_date),
    KEY idx_doc_type (document_type),
    KEY idx_member_date (member_id, transaction_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS supplier_transactions (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    supplier_id INT UNSIGNED NOT NULL,
    transaction_date DATE NOT NULL,
    document_type ENUM('purchase_order','grn','invoice','payment','return','opening_balance','adjustment') NOT NULL,
    document_id INT UNSIGNED NULL,
    document_number VARCHAR(50) NULL,
    description VARCHAR(500) NOT NULL,
    debit DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    credit DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    balance DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    KEY idx_supplier (supplier_id),
    KEY idx_date (transaction_date),
    KEY idx_supplier_date (supplier_id, transaction_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci",
    'down' => "
DROP TABLE IF EXISTS supplier_transactions;
DROP TABLE IF EXISTS customer_transactions",
];
