-- RSVP Submissions table for wedding guest responses
CREATE TABLE IF NOT EXISTS public.rsvp_submissions (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    name TEXT NOT NULL,
    attendance TEXT NOT NULL CHECK (attendance IN ('yes', 'no')),
    plus_ones TEXT,
    message TEXT,
    submitted_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_rsvp_submissions_submitted_at ON public.rsvp_submissions(submitted_at);

ALTER TABLE public.rsvp_submissions ENABLE ROW LEVEL SECURITY;

-- Public can insert (no auth required for wedding RSVP)
DROP POLICY IF EXISTS "public_can_insert_rsvp" ON public.rsvp_submissions;
CREATE POLICY "public_can_insert_rsvp"
ON public.rsvp_submissions
FOR INSERT
TO public
WITH CHECK (true);

-- Only authenticated users (admins) can read submissions
DROP POLICY IF EXISTS "authenticated_can_read_rsvp" ON public.rsvp_submissions;
CREATE POLICY "authenticated_can_read_rsvp"
ON public.rsvp_submissions
FOR SELECT
TO authenticated
USING (true);
