import request, { type RequestOptions } from '/@/utils/request';

export interface StatsParams {
	pending?: number;
	verified?: number;
	rejected?: number;
}

export interface ImageMaterialItem {
	id: number;
	imageId: string;
	accountId: string;
	imageUsage?: string;
	previewUrl?: string;
	verifyStatus: string;
	description?: string;
}

export interface VideoMaterialItem {
	id: number;
	videoId: string;
	accountId: string;
	previewUrl?: string;
	verifyStatus: string;
	description?: string;
}

export interface VerifyLogItem {
	id: number;
	materialType: string;
	materialId: string;
	accountId: string;
	taskId?: string;
	verifyStatus: string;
	suggestion?: number;
	requestParams?: string;
	responseResult?: string;
	errorMsg?: string;
	createdAt: string;
}

export interface PageParams {
	page: number;
	pageSize: number;
	status?: string;
	accountId?: string;
	materialType?: string;
	verifyStatus?: string;
	materialId?: string;
}

export interface ListResponse<T> {
	code: number;
	message: string;
	data: {
		list: T[];
		total: number;
	};
}

export interface StatsResponse {
	code: number;
	message: string;
	data: StatsParams;
}

export function getImageStats(requestOptions?: RequestOptions) {
	return request({
		url: '/cid/material/verify/controller/stats-image',
		method: 'get',
		requestOptions,
	}) as Promise<StatsResponse>;
}

export function getVideoStats(requestOptions?: RequestOptions) {
	return request({
		url: '/cid/material/verify/controller/stats-video',
		method: 'get',
		requestOptions,
	}) as Promise<StatsResponse>;
}

export function getImageList(params: PageParams, requestOptions?: RequestOptions) {
	return request({
		url: '/cid/material/verify/controller/list-image',
		method: 'get',
		params,
		requestOptions,
	}) as Promise<ListResponse<ImageMaterialItem>>;
}

export function getVideoList(params: PageParams, requestOptions?: RequestOptions) {
	return request({
		url: '/cid/material/verify/controller/list-video',
		method: 'get',
		params,
		requestOptions,
	}) as Promise<ListResponse<VideoMaterialItem>>;
}

export function getVerifyLogList(params: PageParams, requestOptions?: RequestOptions) {
	return request({
		url: '/cid/material/verify/controller/list-log',
		method: 'get',
		params,
		requestOptions,
	}) as Promise<ListResponse<VerifyLogItem>>;
}

export function manualVerifyImage(data: { materialId: string }, requestOptions?: RequestOptions) {
	return request({
		url: '/cid/material/verify/controller/manual-verify-image',
		method: 'post',
		data,
		requestOptions,
	});
}

export function manualVerifyVideo(data: { materialId: string }, requestOptions?: RequestOptions) {
	return request({
		url: '/cid/material/verify/controller/manual-verify-video',
		method: 'post',
		data,
		requestOptions,
	});
}

export function pollImageResults(requestOptions?: RequestOptions) {
	return request({
		url: '/cid/yidun/callback/controller/poll-image-results',
		method: 'post',
		requestOptions,
	});
}

export function pollVideoResults(requestOptions?: RequestOptions) {
	return request({
		url: '/cid/yidun/callback/controller/poll-video-results',
		method: 'post',
		requestOptions,
	});
}

export function batchVerifyImage(requestOptions?: RequestOptions) {
	return request({
		url: '/cid/material/verify/controller/batch-verify-image',
		method: 'post',
		requestOptions,
	});
}

export function batchVerifyVideo(requestOptions?: RequestOptions) {
	return request({
		url: '/cid/material/verify/controller/batch-verify-video',
		method: 'post',
		requestOptions,
	});
}

export interface ExportParams {
	materialType?: 'IMAGE' | 'VIDEO';
}

export function exportRejectedMaterials(data: ExportParams = {}, requestOptions?: RequestOptions) {
	return request({
		url: '/cid/material/verify/controller/export-rejected',
		method: 'post',
		data,
		requestOptions,
	});
}

export interface AccountItem {
	accountId: number;
	corporationName: string;
}

export function getAccountList(requestOptions?: RequestOptions) {
	return request({
		url: '/cid/material/verify/controller/list-accounts',
		method: 'post',
		data: {},
		requestOptions,
	});
}
