CREATE TABLE finance_counterparties (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    type ENUM('customer','supplier') NOT NULL DEFAULT 'supplier',
    name VARCHAR(160) NOT NULL,
    trade_name VARCHAR(160) NULL,
    tax_id VARCHAR(32) NULL,
    email VARCHAR(160) NULL,
    phone VARCHAR(40) NULL,
    notes TEXT NULL,
    banking_details JSON NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NULL,
    UNIQUE KEY uq_finance_counterparty_tax (tax_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
