-- ============================================================
-- 快捷提问标签表：前端首页的 quick-asks 标签由后端管理
-- 执行方式：psql -h <host> -U <user> -d pharmacopoeia -f database/quick_asks.sql
-- 通过 backend-java 的 JdbcTemplate 直接操作，不需要 JPA Entity
-- ============================================================
BEGIN;

CREATE TABLE IF NOT EXISTS public.quick_asks (
    id SERIAL PRIMARY KEY,
    label varchar(64) NOT NULL,
    question varchar(256) NOT NULL,
    sort_order int DEFAULT 0,
    is_active boolean DEFAULT true,
    created_at timestamptz DEFAULT now()
);

-- 初始数据（如已存在则跳过）
INSERT INTO public.quick_asks (label, question, sort_order)
SELECT v.label, v.question, v.sort_order
FROM (VALUES
    ('布洛芬', '布洛芬', 1),
    ('甲硝唑', '甲硝唑', 2),
    ('阿莫西林禁忌', '阿莫西林禁忌', 3),
    ('布洛芬用法用量', '布洛芬用法用量', 4),
    ('糠酸莫米松不良反应', '糠酸莫米松不良反应', 5),
    ('青霉素过敏处理', '青霉素过敏处理', 6)
) AS v(label, question, sort_order)
WHERE NOT EXISTS (
    SELECT 1 FROM public.quick_asks WHERE quick_asks.label = v.label
);

COMMIT;
