
-- Add attorney and CPA fields to associations
ALTER TABLE public.associations ADD COLUMN IF NOT EXISTS attorney_name TEXT;
ALTER TABLE public.associations ADD COLUMN IF NOT EXISTS attorney_firm TEXT;
ALTER TABLE public.associations ADD COLUMN IF NOT EXISTS attorney_email TEXT;
ALTER TABLE public.associations ADD COLUMN IF NOT EXISTS attorney_phone TEXT;
ALTER TABLE public.associations ADD COLUMN IF NOT EXISTS cpa_name TEXT;
ALTER TABLE public.associations ADD COLUMN IF NOT EXISTS cpa_firm TEXT;
ALTER TABLE public.associations ADD COLUMN IF NOT EXISTS cpa_email TEXT;
ALTER TABLE public.associations ADD COLUMN IF NOT EXISTS cpa_phone TEXT;
ALTER TABLE public.associations ADD COLUMN IF NOT EXISTS insurance_provider TEXT;
ALTER TABLE public.associations ADD COLUMN IF NOT EXISTS insurance_expiration DATE;
ALTER TABLE public.associations ADD COLUMN IF NOT EXISTS website TEXT;
ALTER TABLE public.associations ADD COLUMN IF NOT EXISTS care_of_address TEXT;
ALTER TABLE public.associations ADD COLUMN IF NOT EXISTS mailing_address TEXT;
ALTER TABLE public.associations ADD COLUMN IF NOT EXISTS contact_email TEXT;

-- Violation types per association
CREATE TABLE IF NOT EXISTS public.violation_types (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  association_id UUID NOT NULL REFERENCES public.associations(id) ON DELETE CASCADE,
  category TEXT NOT NULL,
  article_section TEXT,
  citation_text TEXT,
  requested_action TEXT,
  created_at TIMESTAMPTZ DEFAULT now(),
  updated_at TIMESTAMPTZ DEFAULT now()
);

ALTER TABLE public.violation_types ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Authenticated users can manage violation types"
  ON public.violation_types FOR ALL TO authenticated
  USING (true) WITH CHECK (true);

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