-- 033_ai_tier_aliases.sql — Opprett synops/* tier-aliaser for AI-ruting
--
-- Fire standardnivåer: synops/low, synops/medium, synops/high, synops/extreme
-- Hver tier har en fallback-kjede av providers.
--
-- Ref: docs/oppdrag/admin-komplett.md § AI-ruting

-- Opprett de fire tier-aliasene (separate inserts for ON CONFLICT)
INSERT INTO ai_model_aliases (alias, description) VALUES
    ('synops/low', 'Billig, høyt volum — tekstvasking, metadata, klassifisering')
    ON CONFLICT (alias) DO NOTHING;
INSERT INTO ai_model_aliases (alias, description) VALUES
    ('synops/medium', 'Balansert — oppsummering, research, standard AI-oppgaver')
    ON CONFLICT (alias) DO NOTHING;
INSERT INTO ai_model_aliases (alias, description) VALUES
    ('synops/high', 'Høy kvalitet — chat, kreativ skriving, analyse')
    ON CONFLICT (alias) DO NOTHING;
INSERT INTO ai_model_aliases (alias, description) VALUES
    ('synops/extreme', 'Beste tilgjengelige — kritiske avgjørelser, kompleks resonnering')
    ON CONFLICT (alias) DO NOTHING;

-- synops/low: billige, raske modeller
INSERT INTO ai_model_providers (alias_id, provider, model, api_key_env, priority)
SELECT id, 'gemini', 'gemini/gemini-2.5-flash-lite', 'GEMINI_API_KEY', 1
    FROM ai_model_aliases WHERE alias = 'synops/low';
INSERT INTO ai_model_providers (alias_id, provider, model, api_key_env, priority)
SELECT id, 'xai', 'xai/grok-4-1-fast-non-reasoning', 'XAI_API_KEY', 2
    FROM ai_model_aliases WHERE alias = 'synops/low';
INSERT INTO ai_model_providers (alias_id, provider, model, api_key_env, priority)
SELECT id, 'openrouter', 'openrouter/google/gemini-2.5-flash', 'OPENROUTER_API_KEY', 3
    FROM ai_model_aliases WHERE alias = 'synops/low';

-- synops/medium: gode allround-modeller
INSERT INTO ai_model_providers (alias_id, provider, model, api_key_env, priority)
SELECT id, 'gemini', 'gemini/gemini-2.5-flash', 'GEMINI_API_KEY', 1
    FROM ai_model_aliases WHERE alias = 'synops/medium';
INSERT INTO ai_model_providers (alias_id, provider, model, api_key_env, priority)
SELECT id, 'anthropic', 'anthropic/claude-sonnet-4-20250514', 'ANTHROPIC_API_KEY', 2
    FROM ai_model_aliases WHERE alias = 'synops/medium';
INSERT INTO ai_model_providers (alias_id, provider, model, api_key_env, priority)
SELECT id, 'openrouter', 'openrouter/anthropic/claude-sonnet-4', 'OPENROUTER_API_KEY', 3
    FROM ai_model_aliases WHERE alias = 'synops/medium';

-- synops/high: høykvalitetsmodeller
INSERT INTO ai_model_providers (alias_id, provider, model, api_key_env, priority)
SELECT id, 'anthropic', 'anthropic/claude-sonnet-4-20250514', 'ANTHROPIC_API_KEY', 1
    FROM ai_model_aliases WHERE alias = 'synops/high';
INSERT INTO ai_model_providers (alias_id, provider, model, api_key_env, priority)
SELECT id, 'openrouter', 'openrouter/anthropic/claude-sonnet-4', 'OPENROUTER_API_KEY', 2
    FROM ai_model_aliases WHERE alias = 'synops/high';
INSERT INTO ai_model_providers (alias_id, provider, model, api_key_env, priority)
SELECT id, 'openrouter', 'openrouter/google/gemini-2.5-flash', 'OPENROUTER_API_KEY', 3
    FROM ai_model_aliases WHERE alias = 'synops/high';

-- synops/extreme: beste modeller for kritiske oppgaver
INSERT INTO ai_model_providers (alias_id, provider, model, api_key_env, priority)
SELECT id, 'anthropic', 'anthropic/claude-sonnet-4-20250514', 'ANTHROPIC_API_KEY', 1
    FROM ai_model_aliases WHERE alias = 'synops/extreme';
INSERT INTO ai_model_providers (alias_id, provider, model, api_key_env, priority)
SELECT id, 'openrouter', 'openrouter/anthropic/claude-sonnet-4', 'OPENROUTER_API_KEY', 2
    FROM ai_model_aliases WHERE alias = 'synops/extreme';
