
CREATE TABLE public.billable_expenses (
  id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
  association_id UUID REFERENCES public.associations(id) ON DELETE CASCADE NOT NULL,
  date DATE NOT NULL DEFAULT CURRENT_DATE,
  description TEXT,
  amount NUMERIC(12,2) NOT NULL DEFAULT 0,
  category TEXT,
  billable_type TEXT,
  status TEXT NOT NULL DEFAULT 'pending',
  is_credit BOOLEAN NOT NULL DEFAULT false,
  credit_reason TEXT,
  quantity NUMERIC(10,2) DEFAULT 1,
  unit_price NUMERIC(12,2),
  vendor_name TEXT,
  address TEXT,
  receipt_url TEXT,
  created_by UUID,
  created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
  updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

ALTER TABLE public.billable_expenses ENABLE ROW LEVEL SECURITY;

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

CREATE POLICY "Authenticated users can insert billable_expenses"
  ON public.billable_expenses FOR INSERT TO authenticated WITH CHECK (true);

CREATE POLICY "Authenticated users can update billable_expenses"
  ON public.billable_expenses FOR UPDATE TO authenticated USING (true) WITH CHECK (true);

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