USE db_abos_v0.1;

CREATE TABLE IF NOT EXISTS fact_vat (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    tenant_id INT NOT NULL,
    period VARCHAR(20) NOT NULL,
    currency VARCHAR(10) NOT NULL DEFAULT 'USD',
    sales_vat DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    purchase_vat DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    net_vat DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    due_date DATE NULL,
    status VARCHAR(20) NOT NULL DEFAULT 'Draft',
    notes TEXT NULL,
    created_at TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6),
    created_by INT NULL,
    updated_at TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    updated_by INT NULL,
    is_deleted TINYINT NOT NULL DEFAULT 0,
    INDEX idx_fact_vat_tenant (tenant_id),
    INDEX idx_fact_vat_period (tenant_id, period)
);
