-- cut_task 视频分镜剪切异步任务表
CREATE TABLE IF NOT EXISTS cut_task (
    id BIGSERIAL NOT NULL,
    tenant_id BIGINT NOT NULL DEFAULT 0,
    task_id VARCHAR(64) NOT NULL,
    video_url TEXT NOT NULL,
    shots_json TEXT NOT NULL,
    status VARCHAR(20) NOT NULL DEFAULT 'pending',
    file_url TEXT NOT NULL DEFAULT '',
    file_size BIGINT NOT NULL DEFAULT 0,
    file_name VARCHAR(255) NOT NULL DEFAULT '',
    file_format VARCHAR(32) NOT NULL DEFAULT '',
    file_address_prefix TEXT NOT NULL DEFAULT '',
    duration_str VARCHAR(32) NOT NULL DEFAULT '',
    error_message TEXT,
    callback_url VARCHAR(500) NOT NULL DEFAULT '',
    created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    deleted_at TIMESTAMP WITH TIME ZONE,
    PRIMARY KEY (id)
);

COMMENT ON TABLE cut_task IS '视频分镜剪切异步任务表';
COMMENT ON COLUMN cut_task.task_id IS '任务唯一标识';
COMMENT ON COLUMN cut_task.video_url IS '原始视频URL';
COMMENT ON COLUMN cut_task.shots_json IS '分镜JSON数组';
COMMENT ON COLUMN cut_task.status IS '任务状态:pending/running/success/failed';
COMMENT ON COLUMN cut_task.file_url IS 'MinIO文件访问路径';
COMMENT ON COLUMN cut_task.file_size IS '文件大小(字节)';
COMMENT ON COLUMN cut_task.file_name IS '文件名';
COMMENT ON COLUMN cut_task.file_format IS '文件格式';
COMMENT ON COLUMN cut_task.file_address_prefix IS 'MinIO地址前缀';
COMMENT ON COLUMN cut_task.duration_str IS '剪切后时长';
COMMENT ON COLUMN cut_task.error_message IS '错误信息';
COMMENT ON COLUMN cut_task.callback_url IS '回调地址';
COMMENT ON COLUMN cut_task.created_at IS '创建时间';
COMMENT ON COLUMN cut_task.updated_at IS '更新时间';
COMMENT ON COLUMN cut_task.deleted_at IS '删除时间(软删除)';

CREATE UNIQUE INDEX IF NOT EXISTS idx_cut_task_task_id ON cut_task(task_id);
CREATE INDEX IF NOT EXISTS idx_cut_task_status ON cut_task(status);
CREATE INDEX IF NOT EXISTS idx_cut_task_created_at ON cut_task(created_at);
