-- =============================================
-- 送检日志表 (tencent_content_check_log) - cid数据库
-- =============================================

CREATE TABLE IF NOT EXISTS "tencent_content_check_log" (
    "id" BIGSERIAL PRIMARY KEY,
    "source_table" VARCHAR(64) NOT NULL DEFAULT '',
    "source_id" BIGINT NOT NULL DEFAULT 0,
    "request_url" VARCHAR(512) NOT NULL DEFAULT '',
    "request_param" TEXT NOT NULL DEFAULT '',
    "response_data" TEXT NOT NULL DEFAULT '',
    "status" VARCHAR(32) NOT NULL DEFAULT 'pending',
    "check_time" BIGINT NOT NULL DEFAULT 0,
    "fail_reason" TEXT NOT NULL DEFAULT '',
    "task_id" VARCHAR(128) NOT NULL DEFAULT '',
    "suggestion" INTEGER NOT NULL DEFAULT 0,
    "label" INTEGER NOT NULL DEFAULT 0,
    "result_type" INTEGER NOT NULL DEFAULT 0,
    "duration" BIGINT NOT NULL DEFAULT 0,
    "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMP
);

CREATE INDEX IF NOT EXISTS "idx_content_check_log_source" ON "tencent_content_check_log" ("source_table", "source_id");
CREATE INDEX IF NOT EXISTS "idx_content_check_log_task_id" ON "tencent_content_check_log" ("task_id");
CREATE INDEX IF NOT EXISTS "idx_content_check_log_status" ON "tencent_content_check_log" ("status");
CREATE INDEX IF NOT EXISTS "idx_content_check_log_check_time" ON "tencent_content_check_log" ("check_time");
CREATE INDEX IF NOT EXISTS "idx_content_check_log_created_at" ON "tencent_content_check_log" ("created_at");

COMMENT ON TABLE "tencent_content_check_log" IS '送检日志表';
COMMENT ON COLUMN "tencent_content_check_log"."source_table" IS '来源表标识：tencent_image/tencent_video';
COMMENT ON COLUMN "tencent_content_check_log"."source_id" IS '原数据ID（关联业务表数据）';
COMMENT ON COLUMN "tencent_content_check_log"."request_url" IS '送检请求路径（接口地址）';
COMMENT ON COLUMN "tencent_content_check_log"."request_param" IS '送检入参（完整请求参数，JSON格式）';
COMMENT ON COLUMN "tencent_content_check_log"."response_data" IS '送检出参（完整接口返回结果，JSON格式）';
COMMENT ON COLUMN "tencent_content_check_log"."status" IS '送检状态：pending-待送检, submitting-送检中, success-送检成功, failed-送检失败, completed-检测完成';
COMMENT ON COLUMN "tencent_content_check_log"."check_time" IS '送检时间（时间戳，毫秒）';
COMMENT ON COLUMN "tencent_content_check_log"."fail_reason" IS '失败原因（可选，记录接口报错信息）';
COMMENT ON COLUMN "tencent_content_check_log"."task_id" IS '易盾返回的任务ID';
COMMENT ON COLUMN "tencent_content_check_log"."suggestion" IS '检测结果建议：0-通过，1-嫌疑，2-不通过';
COMMENT ON COLUMN "tencent_content_check_log"."label" IS '检测标签';
COMMENT ON COLUMN "tencent_content_check_log"."result_type" IS '结果类型：1-机器结果，2-人审结果';
COMMENT ON COLUMN "tencent_content_check_log"."duration" IS '送检耗时（毫秒）';
