-- ============================================
-- 团课标签相关表
-- ============================================

-- 团课标签表
CREATE TABLE IF NOT EXISTS course_label (
    id BIGSERIAL PRIMARY KEY,
    label_name VARCHAR(50) NOT NULL,
    color VARCHAR(20) DEFAULT '#1890ff',
    description VARCHAR(200),
    create_by VARCHAR(50),
    update_by VARCHAR(50),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    deleted_at TIMESTAMP
);

-- 团课类型-标签关联表
CREATE TABLE IF NOT EXISTS course_type_label (
    id BIGSERIAL PRIMARY KEY,
    type_id BIGINT NOT NULL,
    label_id BIGINT NOT NULL,
    create_by VARCHAR(50),
    update_by VARCHAR(50),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    deleted_at TIMESTAMP,
    UNIQUE (type_id, label_id)
);

COMMENT ON TABLE course_label IS '团课标签表';
COMMENT ON COLUMN course_label.id IS '主键ID';
COMMENT ON COLUMN course_label.label_name IS '标签名称';
COMMENT ON COLUMN course_label.color IS '标签颜色（十六进制）';
COMMENT ON COLUMN course_label.description IS '标签描述';
COMMENT ON COLUMN course_label.create_by IS '创建人';
COMMENT ON COLUMN course_label.update_by IS '更新人';
COMMENT ON COLUMN course_label.created_at IS '创建时间';
COMMENT ON COLUMN course_label.updated_at IS '更新时间';
COMMENT ON COLUMN course_label.deleted_at IS '删除时间（软删除）';

COMMENT ON TABLE course_type_label IS '团课类型-标签关联表';
COMMENT ON COLUMN course_type_label.id IS '主键ID';
COMMENT ON COLUMN course_type_label.type_id IS '团课类型ID';
COMMENT ON COLUMN course_type_label.label_id IS '标签ID';
COMMENT ON COLUMN course_type_label.create_by IS '创建人';
COMMENT ON COLUMN course_type_label.update_by IS '更新人';
COMMENT ON COLUMN course_type_label.created_at IS '创建时间';
COMMENT ON COLUMN course_type_label.updated_at IS '更新时间';
COMMENT ON COLUMN course_type_label.deleted_at IS '删除时间（软删除）';

-- 创建索引
CREATE INDEX idx_course_label_label_name ON course_label(label_name);
CREATE INDEX idx_course_type_label_type_id ON course_type_label(type_id);
CREATE INDEX idx_course_type_label_label_id ON course_type_label(label_id);

-- 插入初始标签数据
INSERT INTO course_label (label_name, color, description) VALUES
('适合新手', '#52c41a', '适合健身初学者'),
('中级过渡', '#faad14', '适合有一定基础的学员'),
('高级进阶', '#f5222d', '适合高级学员'),
('减脂塑形', '#722ed1', '有助于减脂塑形'),
('增肌强化', '#13c2c2', '有助于增肌强化'),
('柔韧性训练', '#eb2f96', '注重柔韧性提升'),
('核心训练', '#1890ff', '注重核心力量'),
('心肺训练', '#fa8c16', '提升心肺功能'),
('低冲击', '#52c41a', '低冲击运动，适合关节保护'),
('高强度', '#f5222d', '高强度间歇训练'),
('团体互动', '#722ed1', '注重团队协作'),
('私教推荐', '#13c2c2', '私教推荐课程'),
('热门课程', '#ff1493', '人气较高的课程'),
('新课上线', '#00ced1', '新上线的课程')
ON CONFLICT DO NOTHING;