-- Assign deterministic IDs to seeded moderation_log rows so demo reset can preserve baseline logs.

-- RFC-001 description edit
WITH seed_row AS (
    SELECT id
    FROM moderation_log
    WHERE community_id = 'c0000001-0000-0000-0000-000000000001'::uuid
      AND moderator_id = 'd0000001-0000-0000-0000-000000000002'::uuid
      AND target_user_id IS NULL
      AND action_type = 'content_edit'
      AND reason = 'Updated RFC-001 description for clarity'
      AND details = '{"proposal_id": "b0000001-0000-0000-0000-000000000001", "field": "description", "change_type": "formatting"}'::jsonb
    ORDER BY created_at
    LIMIT 1
)
UPDATE moderation_log
SET id = 'f0000001-0000-0000-0000-000000000001'::uuid
WHERE id IN (SELECT id FROM seed_row)
  AND NOT EXISTS (SELECT 1 FROM moderation_log WHERE id = 'f0000001-0000-0000-0000-000000000001'::uuid);

-- Budget proposal thread warning
WITH seed_row AS (
    SELECT id
    FROM moderation_log
    WHERE community_id = 'c0000001-0000-0000-0000-000000000002'::uuid
      AND moderator_id = 'd0000001-0000-0000-0000-000000000002'::uuid
      AND target_user_id = 'd0000002-0000-0000-0000-000000000009'::uuid
      AND action_type = 'warning'
      AND reason = 'Off-topic discussion in budget proposal thread'
      AND details = '{"rule": "community_guidelines_3", "comment_id": "comment_example_001"}'::jsonb
    ORDER BY created_at
    LIMIT 1
)
UPDATE moderation_log
SET id = 'f0000001-0000-0000-0000-000000000002'::uuid
WHERE id IN (SELECT id FROM seed_row)
  AND NOT EXISTS (SELECT 1 FROM moderation_log WHERE id = 'f0000001-0000-0000-0000-000000000002'::uuid);

-- Proposal deadline extension
WITH seed_row AS (
    SELECT id
    FROM moderation_log
    WHERE community_id = 'c0000001-0000-0000-0000-000000000003'::uuid
      AND moderator_id = 'd0000001-0000-0000-0000-000000000002'::uuid
      AND target_user_id IS NULL
      AND action_type = 'proposal_extended'
      AND reason = 'Extended voting deadline by 48 hours due to technical issues'
      AND details = '{"proposal_id": "b0000001-0000-0000-0000-000000000006", "original_end": "2026-01-10T00:00:00Z", "new_end": "2026-01-12T00:00:00Z"}'::jsonb
    ORDER BY created_at
    LIMIT 1
)
UPDATE moderation_log
SET id = 'f0000001-0000-0000-0000-000000000003'::uuid
WHERE id IN (SELECT id FROM seed_row)
  AND NOT EXISTS (SELECT 1 FROM moderation_log WHERE id = 'f0000001-0000-0000-0000-000000000003'::uuid);
