-- ============================================
-- PastPaper Master — COMP2211 course library papers
-- Seed Date: 2026-03-24
-- ============================================
--
-- Before running:
-- 1. Upload the referenced PDFs into the `papers` bucket using the exact storage paths below.
-- 2. Replace __SUPABASE_STORAGE_PUBLIC_BASE_URL__ with your project-specific public base URL.
--
-- Example base URL:
-- https://<project-ref>.supabase.co/storage/v1/object/public/papers
--
-- This seed only inserts canonical, importable COMP2211 course-library papers.

INSERT INTO papers (
  user_id,
  course_code,
  year,
  term,
  exam_type,
  part_label,
  paper_file_url,
  answer_file_url,
  status,
  source_kind,
  source_exam_key,
  source_question_filename,
  source_answer_filename
)
VALUES
  (
    NULL,
    'COMP2211',
    2022,
    'fall',
    'midterm',
    NULL,
    '__SUPABASE_STORAGE_PUBLIC_BASE_URL__/course-library/COMP2211/COMP2211-2022-fall-midterm/paper.pdf',
    '__SUPABASE_STORAGE_PUBLIC_BASE_URL__/course-library/COMP2211/COMP2211-2022-fall-midterm/answer.pdf',
    'uploaded',
    'course_library',
    'COMP2211-2022-fall-midterm',
    '(COMP2211)[2022](f)midterm~=yjz8dxdd^_27002.pdf',
    '(COMP2211)[2022](f)midterm~=yjz8dxdd^_18747.pdf'
  ),
  (
    NULL,
    'COMP2211',
    2022,
    'spring',
    'midterm',
    NULL,
    '__SUPABASE_STORAGE_PUBLIC_BASE_URL__/course-library/COMP2211/COMP2211-2022-spring-midterm/paper.pdf',
    '__SUPABASE_STORAGE_PUBLIC_BASE_URL__/course-library/COMP2211/COMP2211-2022-spring-midterm/answer.pdf',
    'uploaded',
    'course_library',
    'COMP2211-2022-spring-midterm',
    '(COMP2211)[2022](s)midterm~=b8bidkgs^_14629.pdf',
    '(COMP2211)[2022](s)midterm~=6ma030^_89587.pdf'
  ),
  (
    NULL,
    'COMP2211',
    2022,
    'spring',
    'final',
    'A',
    '__SUPABASE_STORAGE_PUBLIC_BASE_URL__/course-library/COMP2211/COMP2211-2022-spring-final-part-a/paper.pdf',
    '__SUPABASE_STORAGE_PUBLIC_BASE_URL__/course-library/COMP2211/COMP2211-2022-spring-final-part-a/answer.pdf',
    'uploaded',
    'course_library',
    'COMP2211-2022-spring-final-part-a',
    '(COMP2211)[2022](s)final~=b8bidkgs^_33018.pdf',
    '(COMP2211)[2022](s)final~=ajou6^_82011.pdf'
  ),
  (
    NULL,
    'COMP2211',
    2022,
    'spring',
    'final',
    'B',
    '__SUPABASE_STORAGE_PUBLIC_BASE_URL__/course-library/COMP2211/COMP2211-2022-spring-final-part-b/paper.pdf',
    '__SUPABASE_STORAGE_PUBLIC_BASE_URL__/course-library/COMP2211/COMP2211-2022-spring-final-part-b/answer.pdf',
    'uploaded',
    'course_library',
    'COMP2211-2022-spring-final-part-b',
    '(COMP2211)[2022](s)final~=b8bidkgs^_40627.pdf',
    '(COMP2211)[2022](s)final~=ajou6^_51199.pdf'
  ),
  (
    NULL,
    'COMP2211',
    2023,
    'spring',
    'midterm',
    NULL,
    '__SUPABASE_STORAGE_PUBLIC_BASE_URL__/course-library/COMP2211/COMP2211-2023-spring-midterm/paper.pdf',
    '__SUPABASE_STORAGE_PUBLIC_BASE_URL__/course-library/COMP2211/COMP2211-2023-spring-midterm/answer.pdf',
    'uploaded',
    'course_library',
    'COMP2211-2023-spring-midterm',
    '(COMP2211)[2023](s)midterm~=bxbidkmj^_26587.pdf',
    '(COMP2211)[2023](s)midterm~clchanbg^_17297.pdf'
  ),
  (
    NULL,
    'COMP2211',
    2024,
    'spring',
    'midterm',
    NULL,
    '__SUPABASE_STORAGE_PUBLIC_BASE_URL__/course-library/COMP2211/COMP2211-2024-spring-midterm/paper.pdf',
    '__SUPABASE_STORAGE_PUBLIC_BASE_URL__/course-library/COMP2211/COMP2211-2024-spring-midterm/answer.pdf',
    'uploaded',
    'course_library',
    'COMP2211-2024-spring-midterm',
    '(COMP2211)[2024](s)midterm~=rcidkjgf^_82003.pdf',
    '(COMP2211)[2024](s)midterm~=ubrzkjmz^_90406.pdf'
  ),
  (
    NULL,
    'COMP2211',
    2024,
    'spring',
    'final',
    NULL,
    '__SUPABASE_STORAGE_PUBLIC_BASE_URL__/course-library/COMP2211/COMP2211-2024-spring-final/paper.pdf',
    '__SUPABASE_STORAGE_PUBLIC_BASE_URL__/course-library/COMP2211/COMP2211-2024-spring-final/answer.pdf',
    'uploaded',
    'course_library',
    'COMP2211-2024-spring-final',
    '(COMP2211)[2024](s)final~=igk5mmg^_90365.pdf',
    '(COMP2211)[2024](s)final~=igk5mmg^_58857.pdf'
  )
ON CONFLICT (source_exam_key)
WHERE source_kind = 'course_library' AND source_exam_key IS NOT NULL
DO UPDATE SET
  course_code = EXCLUDED.course_code,
  year = EXCLUDED.year,
  term = EXCLUDED.term,
  exam_type = EXCLUDED.exam_type,
  part_label = EXCLUDED.part_label,
  paper_file_url = EXCLUDED.paper_file_url,
  answer_file_url = EXCLUDED.answer_file_url,
  status = EXCLUDED.status,
  source_question_filename = EXCLUDED.source_question_filename,
  source_answer_filename = EXCLUDED.source_answer_filename;
