=== LIVE MANIFEST 5/5 — VIEWS + AUTH TRIGGER — RAW LIVE SOURCE ===

VIEW: public.booking_calendar_slots

CREATE OR REPLACE VIEW public.booking_calendar_slots AS
SELECT
    id,
    club_id,
    season_id,
    court_id,
    booking_date,
    start_time,
    end_time,
    booking_type,
    recurring_series_id,
    status,
    is_all_day,
    is_all_courts,
    selected_court_ids,
    is_partner_search_enabled,
    partner_search_utr_min,
    partner_search_utr_max,
    partner_search_players_needed,
    partner_search_status
FROM public.bookings b
WHERE deleted_at IS NULL
  AND status <> 'cancelled'::text
  AND club_id = (
      SELECT c.id
      FROM public.clubs c
      WHERE c.slug = 'bravos-sport-club'::text
      LIMIT 1
  );


VIEW: public.coach_booking_directory

CREATE OR REPLACE VIEW public.coach_booking_directory AS
SELECT
    cp.id AS coach_id,
    up.club_id,
    cp.display_name,
    cp.color,
    cp.min_advance_hours,
    cp.is_active
FROM public.coach_profiles cp
JOIN public.user_profiles up
  ON up.id = cp.user_profile_id
JOIN public.clubs c
  ON c.id = up.club_id
WHERE cp.is_active IS TRUE
  AND c.slug = 'bravos-sport-club'::text;


VIEW: public.partner_finder_directory

CREATE OR REPLACE VIEW public.partner_finder_directory AS
SELECT
    pfp.id,
    pfp.club_id,
    pfp.user_profile_id,
    up.full_name,
    COALESCE(pfp.utr_rating, up.utr_rating) AS utr_rating,
    CASE
        WHEN pfp.show_email_to_players IS TRUE THEN up.email
        ELSE NULL::text
    END AS email,
    CASE
        WHEN pfp.show_phone_to_players IS TRUE THEN up.phone
        ELSE NULL::text
    END AS phone,
    pfp.show_email_to_players,
    pfp.show_phone_to_players,
    pfp.last_partner_search_booking_date
FROM public.partner_finder_profiles pfp
JOIN public.user_profiles up
  ON up.id = pfp.user_profile_id
JOIN public.clubs c
  ON c.id = pfp.club_id
WHERE pfp.partner_search_profile_enabled IS TRUE
  AND c.slug = 'bravos-sport-club'::text;


AUTH TRIGGER: auth.on_auth_user_created_create_profile

CREATE TRIGGER on_auth_user_created_create_profile
AFTER INSERT ON auth.users
FOR EACH ROW
EXECUTE FUNCTION handle_new_auth_user();

=== LIVE MANIFEST 5/5 — VÉGE ===
