-- Site Settings
DROP POLICY IF EXISTS "Adminler site ayarlarını güncelleyebilir" ON site_settings;
CREATE POLICY "Adminler site ayarlarını güncelleyebilir"
  ON site_settings FOR UPDATE
  TO authenticated
  USING (is_admin());

DROP POLICY IF EXISTS "Adminler site ayarlarını oluşturabilir" ON site_settings;
CREATE POLICY "Adminler site ayarlarını oluşturabilir"
  ON site_settings FOR INSERT
  TO authenticated
  WITH CHECK (is_admin());

DROP POLICY IF EXISTS "Admins can insert site settings" ON site_settings;
CREATE POLICY "Admins can insert site settings"
  ON site_settings FOR INSERT
  TO authenticated
  WITH CHECK (is_admin());

-- SEO Settings
DROP POLICY IF EXISTS "Admins can update SEO settings" ON seo_settings;
CREATE POLICY "Admins can update SEO settings"
  ON seo_settings FOR UPDATE
  TO authenticated
  USING (is_admin());

-- Page SEO
DROP POLICY IF EXISTS "Admins can insert page SEO" ON page_seo;
CREATE POLICY "Admins can insert page SEO"
  ON page_seo FOR INSERT
  TO authenticated
  WITH CHECK (is_admin());

DROP POLICY IF EXISTS "Admins can update page SEO" ON page_seo;
CREATE POLICY "Admins can update page SEO"
  ON page_seo FOR UPDATE
  TO authenticated
  USING (is_admin());

DROP POLICY IF EXISTS "Admins can delete page SEO" ON page_seo;
CREATE POLICY "Admins can delete page SEO"
  ON page_seo FOR DELETE
  TO authenticated
  USING (is_admin());

-- URL Redirects
DROP POLICY IF EXISTS "Admins can manage redirects" ON url_redirects;
CREATE POLICY "Admins can manage redirects"
  ON url_redirects FOR ALL
  TO authenticated
  USING (is_admin());

-- Storage Objects (site-assets bucket)
DROP POLICY IF EXISTS "Adminler site varlıklarını yükleyebilir" ON storage.objects;
CREATE POLICY "Adminler site varlıklarını yükleyebilir"
  ON storage.objects FOR INSERT
  TO authenticated
  WITH CHECK (
    bucket_id = 'site-assets' AND
    is_admin()
  );

DROP POLICY IF EXISTS "Adminler site varlıklarını güncelleyebilir" ON storage.objects;
CREATE POLICY "Adminler site varlıklarını güncelleyebilir"
  ON storage.objects FOR UPDATE
  TO authenticated
  USING (
    bucket_id = 'site-assets' AND
    is_admin()
  );

DROP POLICY IF EXISTS "Adminler site varlıklarını silebilir" ON storage.objects;
CREATE POLICY "Adminler site varlıklarını silebilir"
  ON storage.objects FOR DELETE
  TO authenticated
  USING (
    bucket_id = 'site-assets' AND
    is_admin()
  );

-- Other Admin Tables
DROP POLICY IF EXISTS "Admins can view all leads" ON leads;
CREATE POLICY "Admins can view all leads" ON leads FOR SELECT TO authenticated USING (is_admin());

DROP POLICY IF EXISTS "Admins can update leads" ON leads;
CREATE POLICY "Admins can update leads" ON leads FOR UPDATE TO authenticated USING (is_admin());

DROP POLICY IF EXISTS "admin_can_insert_tours" ON tours;
CREATE POLICY "admin_can_insert_tours" ON tours FOR INSERT TO authenticated WITH CHECK (is_admin());

DROP POLICY IF EXISTS "admin_can_update_tours" ON tours;
CREATE POLICY "admin_can_update_tours" ON tours FOR UPDATE TO authenticated USING (is_admin());

DROP POLICY IF EXISTS "admin_can_delete_tours" ON tours;
CREATE POLICY "admin_can_delete_tours" ON tours FOR DELETE TO authenticated USING (is_admin());
