CREATE TABLE billing_cache (
id INTEGER PRIMARY KEY AUTOINCREMENT,
store_key TEXT NOT NULL,
year INTEGER NOT NULL,
month INTEGER NOT NULL,
-- Métricas de uso
total_sessions INTEGER DEFAULT 0,
total_calls INTEGER DEFAULT 0,
total_skus INTEGER DEFAULT 0,
-- Contadores por operación
image_generate_count INTEGER DEFAULT 0,
image_edit_count INTEGER DEFAULT 0,
description_generate_count INTEGER DEFAULT 0,
image_search_count INTEGER DEFAULT 0,
image_upload_count INTEGER DEFAULT 0,
-- Sesiones por tipo
image_generation_sessions INTEGER DEFAULT 0,
description_generation_sessions INTEGER DEFAULT 0,
search_sessions INTEGER DEFAULT 0,
-- Costos
api_cost_total REAL DEFAULT 0,
invoiced_amount REAL DEFAULT 0,
margin REAL DEFAULT 0,
margin_percent REAL DEFAULT 0,
-- Metadata
billing_model TEXT,
calculated_at TEXT DEFAULT (datetime('now')),
UNIQUE(store_key, year, month)
)