-- 1) 风格预设表
CREATE TABLE public.ai_image_style_presets (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  key text NOT NULL UNIQUE,
  label text NOT NULL,
  description text,
  prompt text NOT NULL,
  enabled boolean NOT NULL DEFAULT true,
  sort_order integer NOT NULL DEFAULT 0,
  is_builtin boolean NOT NULL DEFAULT false,
  created_at timestamptz NOT NULL DEFAULT now(),
  updated_at timestamptz NOT NULL DEFAULT now()
);

ALTER TABLE public.ai_image_style_presets ENABLE ROW LEVEL SECURITY;

CREATE POLICY "ai_style_presets_select_all"
ON public.ai_image_style_presets FOR SELECT
USING (true);

CREATE POLICY "ai_style_presets_admin_insert"
ON public.ai_image_style_presets FOR INSERT
TO authenticated
WITH CHECK (public.is_admin(auth.uid()));

CREATE POLICY "ai_style_presets_admin_update"
ON public.ai_image_style_presets FOR UPDATE
TO authenticated
USING (public.is_admin(auth.uid()))
WITH CHECK (public.is_admin(auth.uid()));

CREATE POLICY "ai_style_presets_admin_delete"
ON public.ai_image_style_presets FOR DELETE
TO authenticated
USING (public.is_admin(auth.uid()));

CREATE TRIGGER set_updated_at_ai_image_style_presets
BEFORE UPDATE ON public.ai_image_style_presets
FOR EACH ROW EXECUTE FUNCTION public.set_updated_at();

-- 2) 内置 6 种风格
INSERT INTO public.ai_image_style_presets (key, label, description, prompt, sort_order, is_builtin) VALUES
('studio_white', '纯白棚拍', '经典电商主图，白底居中', 'Studio lighting, clean pure white seamless background, centered composition, subtle soft shadow underneath, catalog-style product shot.', 10, true),
('lifestyle', '生活场景', '真实使用场景，故事感', 'Lifestyle scene photography, product placed in a real-life context with natural environment props, warm ambient lighting, shallow depth of field, story-telling composition.', 20, true),
('flat_lay', '平铺俯拍', '顶视图配饰陈列', 'Top-down flat lay photography, product arranged with complementary props on a textured surface (wood, marble or linen), soft daylight, balanced symmetric composition.', 30, true),
('scene_render', '3D 渲染', '高端 banner 大图风格', '3D scene rendering, product highlighted on a stylized pedestal with gradient backdrop, dramatic studio lights, glossy reflections, modern premium e-commerce hero banner style.', 40, true),
('outdoor_natural', '户外自然光', '黄金时段室外质感', 'Outdoor natural-light photography, product showcased in a relevant outdoor setting, golden hour sunlight, soft bokeh background, authentic and aspirational mood.', 50, true),
('minimal_color', '纯色极简', '莫兰迪纯色背景', 'Minimalist product shot on a solid pastel color background (soft beige / dusty pink / sage green), centered product, clean geometric shadow, modern boutique style.', 60, true);

-- 3) 三视图独立 AI 用途配置
INSERT INTO public.ai_provider_configs (purpose, provider, model, enabled, description, category, display_order)
VALUES (
  'product_image_three_views',
  'lovable',
  'google/gemini-2.5-flash-image',
  true,
  '基于参考图生成商品三视图（正/侧/俯），需支持图生图能力的模型',
  'product',
  20
)
ON CONFLICT (purpose) DO NOTHING;