CREATE TABLE public.cereri_oferta (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  nume text NOT NULL CHECK (char_length(nume) BETWEEN 2 AND 100),
  firma text CHECK (char_length(firma) <= 150),
  tip_entitate text NOT NULL CHECK (char_length(tip_entitate) <= 50),
  servicii text[] NOT NULL DEFAULT '{}',
  documente_lunare text CHECK (char_length(documente_lunare) <= 50),
  angajati text CHECK (char_length(angajati) <= 50),
  telefon text NOT NULL CHECK (char_length(telefon) BETWEEN 6 AND 30),
  email text CHECK (char_length(email) <= 255),
  mesaj text CHECK (char_length(mesaj) <= 1500),
  user_id uuid,
  created_at timestamptz NOT NULL DEFAULT now()
);
GRANT INSERT ON public.cereri_oferta TO anon, authenticated;
GRANT ALL ON public.cereri_oferta TO service_role;
ALTER TABLE public.cereri_oferta ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Oricine poate trimite o cerere" ON public.cereri_oferta FOR INSERT TO anon, authenticated
WITH CHECK (user_id IS NULL OR user_id = auth.uid());