-- =====================================================================
-- 03_seed.sql  —  optional sample data (re-runnable)
-- Fills the reference lists and a few sample programs so the dashboard
-- has something to show. Volunteers cannot be seeded with SQL because
-- they must exist in auth.users — create them via the mobile app or the
-- Supabase Auth dashboard (see README).
-- =====================================================================

-- ---- Skills (from the registration chips) ---------------------------
insert into skills (name) values
  ('Design'), ('Photography'), ('Logistics'),
  ('Teaching'), ('IT'), ('Public Speaking')
on conflict (name) do nothing;

-- ---- Rewards / awards ------------------------------------------------
insert into rewards (name, description, points_required)
select v.name, v.description, v.points
from (values
  ('Bronze Volunteer', 'Completed your first volunteer milestone', 50),
  ('Silver Volunteer', 'Consistent volunteer contribution', 150),
  ('Gold Volunteer', 'Outstanding volunteer dedication', 300),
  ('Star Volunteer of the Month', 'Top contributor for the month', 100)
) as v(name, description, points)
where not exists (select 1 from rewards r where r.name = v.name);

-- ---- Sample programs -------------------------------------------------
insert into programs (title, description, venue, start_at, end_at, slots, merit_value, status)
select v.title, v.descr, v.venue, v.starts, v.ends, v.slots, v.merit, v.status::program_status
from (values
  ('Gotong-Royong Masjid',
   'Community clean-up at the campus mosque. Open to all students — no prior experience required.',
   'Masjid Sultan Idris, UPSI', now() + interval '7 days',  now() + interval '7 days'  + interval '4 hours', 40, 15, 'open'),
  ('Kelas Mengaji',
   'Help run beginner Quran reading classes. Patient, friendly helpers of any background welcome.',
   'Pusat Islam UPSI',          now() + interval '10 days', now() + interval '10 days' + interval '2 hours', 15, 20, 'open'),
  ('Bubur Lambuk Distribution',
   'Cook and distribute bubur lambuk to the campus community during Ramadan.',
   'Dewan Besar UPSI',          now() + interval '14 days', now() + interval '14 days' + interval '5 hours', 50, 25, 'open'),
  ('Blood Donation Drive',
   'Support the campus blood donation drive with registration and logistics.',
   'Dewan Seminar UPSI',        now() + interval '5 days',  now() + interval '5 days'  + interval '6 hours', 30, 20, 'open'),
  ('Media & Publicity Crew',
   'Capture photos and design posters for Pusat Islam programs.',
   'Pusat Islam UPSI',          now() + interval '12 days', now() + interval '12 days' + interval '3 hours', 10, 18, 'open'),
  ('Event Tech Support',
   'Set up sound, projectors and livestreams for Pusat Islam events.',
   'Auditorium UPSI',           now() + interval '3 days',  now() + interval '3 days'  + interval '4 hours', 8, 18, 'open')
) as v(title, descr, venue, starts, ends, slots, merit, status)
where not exists (select 1 from programs p where p.title = v.title);

-- ---- Required skills per program ------------------------------------
insert into program_skills (program_id, skill_id)
select p.id, s.id
from programs p
join skills s on s.name = any (
  case p.title
    when 'Gotong-Royong Masjid'       then array['Logistics']
    when 'Kelas Mengaji'              then array['Teaching','Public Speaking']
    when 'Bubur Lambuk Distribution'  then array['Logistics']
    when 'Blood Donation Drive'       then array['Logistics','IT']
    when 'Media & Publicity Crew'     then array['Design','Photography']
    when 'Event Tech Support'         then array['IT']
    else array[]::text[]
  end
)
where not exists (
  select 1 from program_skills ps where ps.program_id = p.id and ps.skill_id = s.id
);

-- ---- Make yourself an admin (edit the email, then uncomment) ---------
-- update profiles set role = 'admin' where email = 'you@upsi.edu.my';
