-- 腾讯广告视频素材表
CREATE SEQUENCE IF NOT EXISTS tencent_video_id_seq START WITH 1 INCREMENT BY 1;

CREATE TABLE IF NOT EXISTS tencent_video (
    id BIGINT NOT NULL DEFAULT nextval('tencent_video_id_seq'::regclass),
    tenant_id BIGINT NOT NULL DEFAULT 0,
    creator VARCHAR(100) DEFAULT '',
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    updater VARCHAR(100) DEFAULT '',
    updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    deleted_at TIMESTAMP WITH TIME ZONE,
    
    -- 业务字段
    video_id VARCHAR(100) NOT NULL,
    account_id BIGINT NOT NULL,
    width INT,
    height INT,
    video_frames INT,
    video_fps INT,
    video_codec VARCHAR(50),
    video_bit_rate BIGINT,
    audio_codec VARCHAR(50),
    audio_bit_rate BIGINT,
    file_size BIGINT,
    type VARCHAR(50),
    signature VARCHAR(200),
    system_status VARCHAR(50),
    description TEXT,
    preview_url TEXT,
    key_frame_image_url TEXT,
    created_time BIGINT,
    last_modified_time BIGINT,
    video_profile_name VARCHAR(50),
    audio_sample_rate INT,
    max_keyframe_interval INT,
    min_keyframe_interval INT,
    sample_aspect_ratio VARCHAR(50),
    audio_profile_name VARCHAR(50),
    scan_type VARCHAR(50),
    image_duration_millisecond BIGINT,
    audio_duration_millisecond BIGINT,
    source_type VARCHAR(100),
    product_catalog_id VARCHAR(200),
    product_outer_id VARCHAR(200),
    source_reference_id VARCHAR(200),
    owner_account_id VARCHAR(100),
    status VARCHAR(50),
    source_material_id VARCHAR(100),
    new_source_type VARCHAR(100),
    aigc_type INT,
    first_publication_status VARCHAR(100),
    quality_status VARCHAR(100),
    cover_id VARCHAR(100),
    similarity_status VARCHAR(100),
    user_aigc_status VARCHAR(100),
    system_aigc_status VARCHAR(100),
    aigc_source VARCHAR(200),
    aigc_flag VARCHAR(50),
    muse_aigc_version INT,
    
    -- 本地校验状态
    verify_status VARCHAR(20) DEFAULT 'PENDING' NOT NULL,  -- PENDING:待校验, VERIFIED:已校验, REJECTED:已拒绝
    verified_at TIMESTAMP WITH TIME ZONE,                   -- 校验时间
    verified_by VARCHAR(100),                               -- 校验人
    
    PRIMARY KEY (id)
);

COMMENT ON TABLE tencent_video IS '腾讯广告视频素材表';
COMMENT ON COLUMN tencent_video.id IS '主键ID';
COMMENT ON COLUMN tencent_video.tenant_id IS '租户ID';
COMMENT ON COLUMN tencent_video.creator IS '创建人';
COMMENT ON COLUMN tencent_video.created_at IS '创建时间';
COMMENT ON COLUMN tencent_video.updater IS '更新人';
COMMENT ON COLUMN tencent_video.updated_at IS '更新时间';
COMMENT ON COLUMN tencent_video.deleted_at IS '软删除时间';
COMMENT ON COLUMN tencent_video.video_id IS '视频ID';
COMMENT ON COLUMN tencent_video.account_id IS '账户ID';
COMMENT ON COLUMN tencent_video.width IS '宽度';
COMMENT ON COLUMN tencent_video.height IS '高度';
COMMENT ON COLUMN tencent_video.video_frames IS '视频帧数';
COMMENT ON COLUMN tencent_video.video_fps IS '帧率';
COMMENT ON COLUMN tencent_video.video_codec IS '视频编码';
COMMENT ON COLUMN tencent_video.video_bit_rate IS '视频码率';
COMMENT ON COLUMN tencent_video.audio_codec IS '音频编码';
COMMENT ON COLUMN tencent_video.audio_bit_rate IS '音频码率';
COMMENT ON COLUMN tencent_video.file_size IS '文件大小';
COMMENT ON COLUMN tencent_video.type IS '媒体类型';
COMMENT ON COLUMN tencent_video.signature IS '签名';
COMMENT ON COLUMN tencent_video.system_status IS '系统状态';
COMMENT ON COLUMN tencent_video.description IS '描述';
COMMENT ON COLUMN tencent_video.preview_url IS '预览URL';
COMMENT ON COLUMN tencent_video.key_frame_image_url IS '关键帧图片URL';
COMMENT ON COLUMN tencent_video.created_time IS '创建时间戳';
COMMENT ON COLUMN tencent_video.last_modified_time IS '最后修改时间戳';
COMMENT ON COLUMN tencent_video.video_profile_name IS '视频配置名称';
COMMENT ON COLUMN tencent_video.audio_sample_rate IS '音频采样率';
COMMENT ON COLUMN tencent_video.max_keyframe_interval IS '最大关键帧间隔';
COMMENT ON COLUMN tencent_video.min_keyframe_interval IS '最小关键帧间隔';
COMMENT ON COLUMN tencent_video.sample_aspect_ratio IS '示例宽高比';
COMMENT ON COLUMN tencent_video.audio_profile_name IS '音频配置名称';
COMMENT ON COLUMN tencent_video.scan_type IS '扫描类型';
COMMENT ON COLUMN tencent_video.image_duration_millisecond IS '图片时长（毫秒）';
COMMENT ON COLUMN tencent_video.audio_duration_millisecond IS '音频时长（毫秒）';
COMMENT ON COLUMN tencent_video.source_type IS '来源类型';
COMMENT ON COLUMN tencent_video.product_catalog_id IS '产品目录ID';
COMMENT ON COLUMN tencent_video.product_outer_id IS '产品外部ID';
COMMENT ON COLUMN tencent_video.source_reference_id IS '源引用ID';
COMMENT ON COLUMN tencent_video.owner_account_id IS '所有者账户ID';
COMMENT ON COLUMN tencent_video.status IS '状态';
COMMENT ON COLUMN tencent_video.source_material_id IS '源素材ID';
COMMENT ON COLUMN tencent_video.new_source_type IS '新来源类型';
COMMENT ON COLUMN tencent_video.aigc_type IS 'AIGC类型';
COMMENT ON COLUMN tencent_video.first_publication_status IS '首次发布状态';
COMMENT ON COLUMN tencent_video.quality_status IS '质量状态';
COMMENT ON COLUMN tencent_video.cover_id IS '封面ID';
COMMENT ON COLUMN tencent_video.similarity_status IS '相似度状态';
COMMENT ON COLUMN tencent_video.user_aigc_status IS '用户AIGC状态';
COMMENT ON COLUMN tencent_video.system_aigc_status IS '系统AIGC状态';
COMMENT ON COLUMN tencent_video.aigc_source IS 'AIGC来源';
COMMENT ON COLUMN tencent_video.aigc_flag IS 'AIGC标志';
COMMENT ON COLUMN tencent_video.muse_aigc_version IS 'Muse AIGC版本';

-- 唯一索引：根据video_id和account_id判断是否存在
CREATE UNIQUE INDEX idx_tencent_video_video_account ON tencent_video(tenant_id, video_id, account_id);
CREATE INDEX idx_tencent_video_account_id ON tencent_video(account_id);
CREATE INDEX idx_tencent_video_last_modified ON tencent_video(last_modified_time);
CREATE INDEX idx_tencent_video_status ON tencent_video(status);
