-- Rename ai_model_writing to ai_model_websearch
ALTER TABLE settings RENAME COLUMN ai_model_writing TO ai_model_websearch;

-- Restructure admin_providers: rename 'models' to 'models_scraping', add 'models_websearch'
-- First, rename the existing models column
ALTER TABLE admin_providers RENAME COLUMN models TO models_scraping;

-- Add the new models_websearch column (copy from models_scraping initially)
ALTER TABLE admin_providers ADD COLUMN models_websearch JSONB NOT NULL DEFAULT '[]'::jsonb;

-- Copy models_scraping to models_websearch for all providers (same list initially)
UPDATE admin_providers SET models_websearch = models_scraping;

-- Update OpenAI with GPT-5 generation models
UPDATE admin_providers SET
    models_scraping = '[
        {"model_id": "gpt-5.4-mini", "display_name": "GPT-5.4 Mini", "is_default": false},
        {"model_id": "gpt-5.4-nano", "display_name": "GPT-5.4 Nano", "is_default": false},
        {"model_id": "gpt-5-mini", "display_name": "GPT-5 Mini", "is_default": false},
        {"model_id": "gpt-5-nano", "display_name": "GPT-5 Nano", "is_default": true}
    ]'::jsonb,
    models_websearch = '[
        {"model_id": "gpt-5.4", "display_name": "GPT-5.4", "is_default": false},
        {"model_id": "gpt-5.4-mini", "display_name": "GPT-5.4 Mini", "is_default": false},
        {"model_id": "gpt-5.2", "display_name": "GPT-5.2", "is_default": false},
        {"model_id": "gpt-5.1", "display_name": "GPT-5.1", "is_default": true},
        {"model_id": "gpt-5-mini", "display_name": "GPT-5 Mini", "is_default": false},
        {"model_id": "gpt-5", "display_name": "GPT-5", "is_default": false}
    ]'::jsonb
WHERE provider_name = 'openai';
