-- Add brand book / cover page fields to companies
ALTER TABLE companies
  ADD COLUMN IF NOT EXISTS address text,
  ADD COLUMN IF NOT EXISTS contact_name text,
  ADD COLUMN IF NOT EXISTS contact_email text,
  ADD COLUMN IF NOT EXISTS contact_phone text,
  ADD COLUMN IF NOT EXISTS client_logo_url text;

-- Create public bucket for company logos
DO $$
BEGIN
  IF NOT EXISTS (SELECT 1 FROM storage.buckets WHERE id = 'company-logos') THEN
    INSERT INTO storage.buckets (id, name, public) VALUES ('company-logos', 'company-logos', true);
  END IF;
END $$;

-- Storage policies for company-logos
DROP POLICY IF EXISTS "Authenticated users can manage company logos" ON storage.objects;
DROP POLICY IF EXISTS "Public can read company logos" ON storage.objects;

CREATE POLICY "Authenticated users can manage company logos"
  ON storage.objects FOR ALL
  TO authenticated
  USING (bucket_id = 'company-logos')
  WITH CHECK (bucket_id = 'company-logos');

CREATE POLICY "Public can read company logos"
  ON storage.objects FOR SELECT
  USING (bucket_id = 'company-logos');
