-- Ledger entries table for double-entry accounting

CREATE TABLE IF NOT EXISTS ledger_entries (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    customer_id UUID NOT NULL,
    account_type VARCHAR(20) NOT NULL CHECK (account_type IN ('asset', 'liability', 'equity')),
    amount NUMERIC(78, 0) NOT NULL,
    currency VARCHAR(10) NOT NULL DEFAULT 'USD',
    description TEXT,
    reference VARCHAR(255),
    side VARCHAR(10) NOT NULL CHECK (side IN ('debit', 'credit')),
    created_at TIMESTAMP DEFAULT NOW()
);

CREATE INDEX idx_ledger_customer ON ledger_entries(customer_id);
CREATE INDEX idx_ledger_account_type ON ledger_entries(account_type);
CREATE INDEX idx_ledger_reference ON ledger_entries(reference);
CREATE INDEX idx_ledger_created_at ON ledger_entries(created_at);

