-- ============================================================
-- YaoAI Comic Studio — M2 项目管理表
-- ============================================================

CREATE TABLE IF NOT EXISTS projects
(
    id          BIGINT UNSIGNED  NOT NULL COMMENT '项目 ID',
    tenant_id   BIGINT UNSIGNED  NOT NULL COMMENT '所属租户',
    user_id     BIGINT UNSIGNED  NOT NULL COMMENT '创建者',
    name        VARCHAR(200)     NOT NULL COMMENT '项目名称',
    description TEXT                      COMMENT '项目描述',
    status      VARCHAR(20)      NOT NULL DEFAULT 'draft' COMMENT 'draft/processing/completed/failed',
    style       VARCHAR(50)               DEFAULT NULL COMMENT '已选风格 slug',
    cover_key   VARCHAR(500)              DEFAULT NULL COMMENT '封面图 TOS key',
    created_at  DATETIME(3)      NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    updated_at  DATETIME(3)      NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
    deleted_at  DATETIME(3)               DEFAULT NULL,
    PRIMARY KEY (id),
    KEY idx_tenant_status (tenant_id, status),
    KEY idx_user_id (user_id),
    KEY idx_created_at (created_at)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT '项目表';

CREATE TABLE IF NOT EXISTS project_assets
(
    id            BIGINT UNSIGNED  NOT NULL COMMENT '素材 ID',
    project_id    BIGINT UNSIGNED  NOT NULL,
    tenant_id     BIGINT UNSIGNED  NOT NULL,
    name          VARCHAR(255)     NOT NULL COMMENT '显示名称',
    original_name VARCHAR(255)     NOT NULL COMMENT '原始文件名',
    asset_type    VARCHAR(50)      NOT NULL DEFAULT 'other' COMMENT 'script/image/reference/audio/other',
    mime_type     VARCHAR(100)              DEFAULT NULL,
    file_size     BIGINT UNSIGNED           DEFAULT NULL COMMENT '字节数',
    tos_key       VARCHAR(500)     NOT NULL COMMENT 'TOS object key',
    created_at    DATETIME(3)      NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    PRIMARY KEY (id),
    KEY idx_project_id (project_id),
    KEY idx_tenant_id (tenant_id)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT '项目素材表';
