-- RLS: 医疗商城独立分类与商品分类关联
-- 执行阶段: 20_rls

ALTER TABLE public.medical_mall_categories ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.medical_mall_product_categories ENABLE ROW LEVEL SECURITY;

DROP POLICY IF EXISTS medical_mall_categories_public_select_active ON public.medical_mall_categories;
CREATE POLICY medical_mall_categories_public_select_active
ON public.medical_mall_categories
FOR SELECT
TO anon, authenticated
USING (
    deleted_at IS NULL
    AND is_active = TRUE
    AND compliance_type <> 'rx_hidden'
);

DROP POLICY IF EXISTS medical_mall_product_categories_public_select_active ON public.medical_mall_product_categories;
CREATE POLICY medical_mall_product_categories_public_select_active
ON public.medical_mall_product_categories
FOR SELECT
TO anon, authenticated
USING (deleted_at IS NULL);