-- 商品表
CREATE TABLE seller_listing (
    id              BIGINT PRIMARY KEY COMMENT '商品ID',
    seller_id       BIGINT NOT NULL COMMENT '卖家ID',
    title           VARCHAR(255) NOT NULL COMMENT '商品标题',
    description     TEXT COMMENT '商品描述',
    price           DECIMAL(10,2) COMMENT '价格',
    cover           VARCHAR(200) COMMENT '封面图URL',
    view_count      INT DEFAULT 0 COMMENT '浏览量',
    status          INT(1) DEFAULT 0 COMMENT '状态: 0-草稿, 1-已发布, 2-已删除',
    create_time     DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    update_time     DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    deleted         INT(1) DEFAULT 0 COMMENT '是否删除：0-否，1-是',
    design_for      VARCHAR(50) COMMENT '适用性别: male/female',
    product_category JSON COMMENT '商品分类列表',
    INDEX idx_seller_id (seller_id),
    INDEX idx_status (status),
    INDEX idx_deleted (deleted)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商品表';

-- 商品图片表
CREATE TABLE seller_listing_image (
    id              BIGINT PRIMARY KEY COMMENT '图片ID',
    listing_id      BIGINT NOT NULL COMMENT '商品ID',
    category        VARCHAR(50) NOT NULL COMMENT '图片类别: cover/main_product/product/sketch/apparel',
    image_url       VARCHAR(500) NOT NULL COMMENT '图片URL',
    sort_order      INT DEFAULT 0 COMMENT '排序',
    is_selected     INT(1) DEFAULT 0 COMMENT '是否选中: 0-未选中, 1-选中(仅product有效)',
    create_time     DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    deleted         INT(1) DEFAULT 0 COMMENT '是否删除：0-否，1-是',
    INDEX idx_listing_id (listing_id),
    INDEX idx_deleted (deleted)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商品图片表';

-- 设计师表
CREATE TABLE seller_designer (
    id              BIGINT PRIMARY KEY COMMENT '设计师ID',
    user_id         BIGINT NOT NULL COMMENT '用户ID',
    shop_name       VARCHAR(100) NOT NULL COMMENT '店铺名称',
    avatar          VARCHAR(200) COMMENT '店铺头像URL',
    brand_banner    VARCHAR(200) COMMENT '品牌Banner URL',
    owner_name      VARCHAR(100) COMMENT '所有者全名',
    email           VARCHAR(100) COMMENT '邮箱',
    mobile          VARCHAR(30) COMMENT '手机号',
    social_links    JSON COMMENT '作品集/社交媒体链接',
    description      TEXT COMMENT '设计师简介',
    apply_status    INT(1) DEFAULT 0 COMMENT '申请状态: 0-待审核, 1-审核通过, 2-审核拒绝',
    audit_remark    VARCHAR(500) COMMENT '审核备注',
    audit_time      DATETIME COMMENT '审核时间',
    status          INT(1) DEFAULT 1 COMMENT '状态: 0-禁用, 1-启用',
    create_time     DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    update_time     DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    deleted         INT(1) DEFAULT 0 COMMENT '是否删除: 0-否, 1-是',
    INDEX idx_user_id (user_id),
    INDEX idx_apply_status (apply_status),
    INDEX idx_status (status),
    INDEX idx_deleted (deleted)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='设计师表';

-- 订单主表
CREATE TABLE seller_orders (
    id              BIGINT PRIMARY KEY COMMENT '主键ID',
    seller_id       BIGINT NOT NULL COMMENT '卖家ID',
    buyer_id        BIGINT NOT NULL COMMENT '买家ID',
    status          INT DEFAULT 0 COMMENT '订单状态: 0-未支付, 1-已支付, 2-已取消',
    shop_name       VARCHAR(100) COMMENT '店铺名称',
    total_price     DECIMAL(10,2) COMMENT '订单总金额(HK$)',
    buyer_username  VARCHAR(100) COMMENT '买家账号',
    total_items     INT COMMENT '商品总数量',
    total_views     BIGINT DEFAULT 0 COMMENT '总浏览量',
    create_time     DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '下单时间',
    update_time     DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    deleted         INT(1) DEFAULT 0 COMMENT '是否删除：0-否，1-是',
    INDEX idx_seller_id (seller_id),
    INDEX idx_deleted (deleted),
    INDEX idx_create_time (create_time)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单主表';

-- 订单商品明细表
CREATE TABLE seller_order_item (
    id              BIGINT PRIMARY KEY COMMENT '主键ID',
    order_id        BIGINT NOT NULL COMMENT '订单ID',
    seller_id       BIGINT NOT NULL COMMENT '卖家ID',
    buyer_id        BIGINT NOT NULL COMMENT '买家ID',
    listing_id      BIGINT NOT NULL COMMENT '商品ID',
    listing_name    VARCHAR(255) COMMENT '商品名称',
    thumbnail_url   VARCHAR(200) COMMENT '商品缩略图URL',
    price           DECIMAL(10,2) COMMENT '成交单价(HK$)',
    create_time     DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    deleted         INT(1) DEFAULT 0 COMMENT '是否删除：0-否，1-是',
    product_category JSON COMMENT '商品分类列表',
    INDEX idx_order_id (order_id),
    INDEX idx_listing_id (listing_id),
    INDEX idx_deleted (deleted)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单商品明细表';
