CREATE TABLE finance_daily_snapshots (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    snapshot_date DATE NOT NULL,
    scope_type ENUM('organization','broker','origin','campaign') NOT NULL DEFAULT 'organization',
    scope_key VARCHAR(80) NULL,
    metrics JSON NOT NULL,
    generated_at DATETIME NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NULL,
    UNIQUE KEY uq_finance_snapshot_scope (snapshot_date, scope_type, scope_key),
    INDEX idx_finance_snapshot_generated (generated_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
