-- Utviklingsdata for lokalt testmiljø.
-- Kjøres etter 0001_initial_schema.sql.
-- IKKE bruk i produksjon.

BEGIN;

-- Test-workspace
INSERT INTO workspaces (id, name, slug) VALUES
    ('a0000000-0000-0000-0000-000000000001', 'Sidelinja Podcast', 'sidelinja');

-- Vegard (Authentik sub claim + dev-user alias)
INSERT INTO users (authentik_id, display_name) VALUES
    ('f0c628bf-2dde-42a9-86f9-6a308248a38f', 'Vegard Nøtnæs'),
    ('dev-user-1', 'Vegard (dev)');

-- Koble begge bruker-IDer til workspace
INSERT INTO workspace_members (workspace_id, user_id, role) VALUES
    ('a0000000-0000-0000-0000-000000000001', 'f0c628bf-2dde-42a9-86f9-6a308248a38f', 'owner'),
    ('a0000000-0000-0000-0000-000000000001', 'dev-user-1', 'owner');

-- Workspace-rot-node (parent for workspace-level channels)
INSERT INTO nodes (id, workspace_id, node_type) VALUES
    ('a0000000-0000-0000-0000-000000000010', 'a0000000-0000-0000-0000-000000000001', 'channel');

-- Generell chat-kanal
INSERT INTO nodes (id, workspace_id, node_type) VALUES
    ('a0000000-0000-0000-0000-000000000011', 'a0000000-0000-0000-0000-000000000001', 'channel');
INSERT INTO channels (id, parent_id, name) VALUES
    ('a0000000-0000-0000-0000-000000000011', 'a0000000-0000-0000-0000-000000000010', 'Generelt');

-- Redaksjons-kanal
INSERT INTO nodes (id, workspace_id, node_type) VALUES
    ('a0000000-0000-0000-0000-000000000012', 'a0000000-0000-0000-0000-000000000001', 'channel');
INSERT INTO channels (id, parent_id, name) VALUES
    ('a0000000-0000-0000-0000-000000000012', 'a0000000-0000-0000-0000-000000000010', 'Redaksjonen');

-- Default-sider for workspace
UPDATE workspaces SET settings = jsonb_set(
    COALESCE(settings, '{}'::jsonb),
    '{pages}',
    '[
        {
            "slug": "redaksjonen",
            "title": "Redaksjonen",
            "icon": "📰",
            "layout": "2-1",
            "blocks": [
                {"id": "chat-1", "type": "chat", "title": "Redaksjonschat", "props": {"channelId": "a0000000-0000-0000-0000-000000000012"}},
                {"id": "kanban-1", "type": "kanban", "title": "Planlegging"}
            ]
        },
        {
            "slug": "research",
            "title": "Research",
            "icon": "🔍",
            "layout": "2-col",
            "blocks": [
                {"id": "research-1", "type": "research", "title": "Research-klipp"},
                {"id": "graph-1", "type": "graph", "title": "Kunnskapsgraf"}
            ]
        }
    ]'::jsonb
) WHERE slug = 'sidelinja';

COMMIT;
