-- 002_seed_data.sql
-- Seed-data: Vegards brukernode, auth_identity, Sidelinja samlings-node, og owner-edge.
-- Ref: docs/primitiver/nodes.md, docs/primitiver/edges.md

BEGIN;

-- =============================================================================
-- Vegards brukernode
-- =============================================================================

INSERT INTO nodes (id, node_kind, title, visibility, metadata)
VALUES (
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
    'person',
    'Vegard',
    'discoverable',
    '{"display_name": "Vegard"}'::jsonb
);

-- =============================================================================
-- Auth-identitet (bro mellom Authentik-sesjon og Vegards node)
-- authentik_sub oppdateres når Authentik konfigureres i oppgave 1.5.
-- =============================================================================

INSERT INTO auth_identities (node_id, authentik_sub, email)
VALUES (
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
    'placeholder-will-be-updated-in-task-1.5',
    'vnotnes@pm.me'
);

-- =============================================================================
-- Sidelinja samlings-node
-- =============================================================================

INSERT INTO nodes (id, node_kind, title, visibility, metadata, created_by)
VALUES (
    'b1eebc99-9c0b-4ef8-bb6d-6bb9bd380a22',
    'collection',
    'Sidelinja',
    'readable',
    '{}'::jsonb,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'
);

-- =============================================================================
-- Owner-edge: Vegard eier Sidelinja
-- =============================================================================

INSERT INTO edges (id, source_id, target_id, edge_type, created_by)
VALUES (
    'c2eebc99-9c0b-4ef8-bb6d-6bb9bd380a33',
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',  -- Vegard
    'b1eebc99-9c0b-4ef8-bb6d-6bb9bd380a22',  -- Sidelinja
    'owner',
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'   -- Vegard
);

-- =============================================================================
-- Oppdater tilgangsmatrisen: Vegard har owner-tilgang til Sidelinja
-- =============================================================================

SELECT recompute_access(
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',  -- subject: Vegard
    'b1eebc99-9c0b-4ef8-bb6d-6bb9bd380a22',  -- object: Sidelinja
    'owner',
    'c2eebc99-9c0b-4ef8-bb6d-6bb9bd380a33'   -- via: owner-edge
);

COMMIT;
