-- 腾讯广告图片素材表
CREATE SEQUENCE IF NOT EXISTS tencent_image_id_seq START WITH 1 INCREMENT BY 1;

CREATE TABLE IF NOT EXISTS tencent_image (
    id BIGINT NOT NULL DEFAULT nextval('tencent_image_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,
    
    -- 业务字段
    image_id VARCHAR(100) NOT NULL,
    account_id BIGINT NOT NULL,
    width INT,
    height INT,
    file_size BIGINT,
    type VARCHAR(50),
    signature VARCHAR(200),
    description TEXT,
    source_signature VARCHAR(200),
    preview_url TEXT,
    thumb_preview_url TEXT,
    source_type VARCHAR(100),
    image_usage VARCHAR(100),
    created_time BIGINT,
    last_modified_time BIGINT,
    product_catalog_id BIGINT,
    product_outer_id VARCHAR(200),
    source_reference_id VARCHAR(200),
    owner_account_id VARCHAR(100),
    status VARCHAR(50),
    sample_aspect_ratio VARCHAR(50),
    source_material_id VARCHAR(100),
    new_source_type VARCHAR(100),
    first_publication_status VARCHAR(100),
    quality_status 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,
    aigc_type INT,
    
    PRIMARY KEY (id)
);

COMMENT ON TABLE tencent_image IS '腾讯广告图片素材表';
COMMENT ON COLUMN tencent_image.id IS '主键ID';
COMMENT ON COLUMN tencent_image.tenant_id IS '租户ID';
COMMENT ON COLUMN tencent_image.creator IS '创建人';
COMMENT ON COLUMN tencent_image.created_at IS '创建时间';
COMMENT ON COLUMN tencent_image.updater IS '更新人';
COMMENT ON COLUMN tencent_image.updated_at IS '更新时间';
COMMENT ON COLUMN tencent_image.deleted_at IS '软删除时间';
COMMENT ON COLUMN tencent_image.image_id IS '图片ID';
COMMENT ON COLUMN tencent_image.account_id IS '账户ID';
COMMENT ON COLUMN tencent_image.width IS '宽度';
COMMENT ON COLUMN tencent_image.height IS '高度';
COMMENT ON COLUMN tencent_image.file_size IS '文件大小';
COMMENT ON COLUMN tencent_image.type IS '图片类型';
COMMENT ON COLUMN tencent_image.signature IS '签名';
COMMENT ON COLUMN tencent_image.description IS '描述';
COMMENT ON COLUMN tencent_image.source_signature IS '源签名';
COMMENT ON COLUMN tencent_image.preview_url IS '预览URL';
COMMENT ON COLUMN tencent_image.thumb_preview_url IS '缩略图URL';
COMMENT ON COLUMN tencent_image.source_type IS '来源类型';
COMMENT ON COLUMN tencent_image.image_usage IS '图片用途';
COMMENT ON COLUMN tencent_image.created_time IS '创建时间戳';
COMMENT ON COLUMN tencent_image.last_modified_time IS '最后修改时间戳';
COMMENT ON COLUMN tencent_image.product_catalog_id IS '产品目录ID';
COMMENT ON COLUMN tencent_image.product_outer_id IS '产品外部ID';
COMMENT ON COLUMN tencent_image.source_reference_id IS '源引用ID';
COMMENT ON COLUMN tencent_image.owner_account_id IS '所有者账户ID';
COMMENT ON COLUMN tencent_image.status IS '状态';
COMMENT ON COLUMN tencent_image.sample_aspect_ratio IS '示例宽高比';
COMMENT ON COLUMN tencent_image.source_material_id IS '源素材ID';
COMMENT ON COLUMN tencent_image.new_source_type IS '新来源类型';
COMMENT ON COLUMN tencent_image.first_publication_status IS '首次发布状态';
COMMENT ON COLUMN tencent_image.quality_status IS '质量状态';
COMMENT ON COLUMN tencent_image.similarity_status IS '相似度状态';
COMMENT ON COLUMN tencent_image.user_aigc_status IS '用户AIGC状态';
COMMENT ON COLUMN tencent_image.system_aigc_status IS '系统AIGC状态';
COMMENT ON COLUMN tencent_image.aigc_source IS 'AIGC来源';
COMMENT ON COLUMN tencent_image.aigc_flag IS 'AIGC标志';
COMMENT ON COLUMN tencent_image.muse_aigc_version IS 'Muse AIGC版本';
COMMENT ON COLUMN tencent_image.aigc_type IS 'AIGC类型';

-- 唯一索引：根据image_id和account_id判断是否存在
CREATE UNIQUE INDEX idx_tencent_image_image_account ON tencent_image(tenant_id, image_id, account_id);
CREATE INDEX idx_tencent_image_account_id ON tencent_image(account_id);
CREATE INDEX idx_tencent_image_last_modified ON tencent_image(last_modified_time);
CREATE INDEX idx_tencent_image_status ON tencent_image(status);
