CREATE TABLE public.annual_meetings (
  id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
  association_id UUID NOT NULL REFERENCES public.associations(id) ON DELETE CASCADE,
  total_units INTEGER NOT NULL DEFAULT 0,
  quorum_percent NUMERIC NOT NULL DEFAULT 0,
  quorum_needed INTEGER NOT NULL DEFAULT 0,
  meeting_date DATE NULL,
  notes TEXT NULL,
  created_by UUID NULL,
  created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
  updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()
);

ALTER TABLE public.annual_meetings ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Authenticated users can view annual meetings"
  ON public.annual_meetings FOR SELECT TO authenticated USING (true);

CREATE POLICY "Authenticated users can create annual meetings"
  ON public.annual_meetings FOR INSERT TO authenticated WITH CHECK (true);

CREATE POLICY "Authenticated users can update annual meetings"
  ON public.annual_meetings FOR UPDATE TO authenticated USING (true);

CREATE POLICY "Authenticated users can delete annual meetings"
  ON public.annual_meetings FOR DELETE TO authenticated USING (true);

CREATE TRIGGER update_annual_meetings_updated_at
  BEFORE UPDATE ON public.annual_meetings
  FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();