-- 创建用户作品表
CREATE TABLE IF NOT EXISTS user_works (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(100) NOT NULL COMMENT '用户名',
    task_id VARCHAR(50) NOT NULL UNIQUE COMMENT '任务ID',
    work_type ENUM('TEXT_TO_VIDEO', 'IMAGE_TO_VIDEO', 'STORYBOARD_VIDEO') NOT NULL COMMENT '作品类型',
    title VARCHAR(200) COMMENT '作品标题',
    description TEXT COMMENT '作品描述',
    prompt TEXT COMMENT '生成提示词',
    result_url VARCHAR(500) COMMENT '结果视频URL',
    thumbnail_url VARCHAR(500) COMMENT '缩略图URL',
    duration VARCHAR(10) COMMENT '视频时长',
    aspect_ratio VARCHAR(10) COMMENT '宽高比',
    quality VARCHAR(20) COMMENT '画质',
    file_size VARCHAR(20) COMMENT '文件大小',
    points_cost INT NOT NULL DEFAULT 0 COMMENT '消耗积分',
    status ENUM('PROCESSING', 'COMPLETED', 'FAILED', 'DELETED') NOT NULL DEFAULT 'PROCESSING' COMMENT '作品状态',
    is_public BOOLEAN NOT NULL DEFAULT FALSE COMMENT '是否公开',
    view_count INT NOT NULL DEFAULT 0 COMMENT '浏览次数',
    like_count INT NOT NULL DEFAULT 0 COMMENT '点赞次数',
    download_count INT NOT NULL DEFAULT 0 COMMENT '下载次数',
    tags VARCHAR(500) COMMENT '标签',
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    completed_at DATETIME COMMENT '完成时间',
    
    INDEX idx_username_status (username, status),
    INDEX idx_task_id (task_id),
    INDEX idx_work_type (work_type),
    INDEX idx_is_public_status (is_public, status),
    INDEX idx_created_at (created_at),
    INDEX idx_view_count (view_count),
    INDEX idx_like_count (like_count),
    INDEX idx_tags (tags),
    INDEX idx_prompt (prompt(100))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户作品表';
