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

export interface ScheduleListParams {
	pageNum: number;
	pageSize: number;
	anchorId?: string;
	accountId?: string;
	status?: number;
}

export interface ScheduleSaveParams {
	id?: string;
	anchorId: string;
	accountId: string;
	productId?: number;
	orderId?: number;
	startTime: string;
	endTime: string;
	status?: number;
	remark?: string;
}

export interface ScheduleItem {
	id: string;
	anchorId: string;
	anchorName: string;
	accountId: string;
	accountName: string;
	platform: string;
	startTime: number;
	endTime: number;
	status: number;
	statusName: string;
	productId: number;
	orderId: number;
	remark: string;
	createdAt: number;
	updatedAt: number;
}

export interface ScheduleDetail {
	id: string;
	tenantId: number;
	creator: string;
	createdAt: string;
	updater: string;
	updatedAt: string;
	deletedAt: string | null;
	anchorId: string;
	accountId: string;
	startTime: string;
	endTime: string;
	status: number;
	productId: number;
	orderId: number;
	remark: string;
}

export interface ScheduleListResult {
	list: ScheduleItem[];
	total: number;
}

export interface ScheduleListResponse {
	code: number;
	message: string;
	data: ScheduleListResult;
}

export interface ScheduleDetailResponse {
	code: number;
	message: string;
	data: ScheduleDetail;
}

export function getScheduleList(params: ScheduleListParams, requestOptions?: RequestOptions): Promise<ScheduleListResponse> {
	return request({
		url: '/erp/schedule/controller/listSchedules',
		method: 'get',
		params,
		requestOptions,
	}) as Promise<ScheduleListResponse>;
}

export function getScheduleDetail(params: { id: string }, requestOptions?: RequestOptions): Promise<ScheduleDetailResponse> {
	return request({
		url: '/erp/schedule/controller/getSchedule',
		method: 'get',
		params,
		requestOptions,
	}) as Promise<ScheduleDetailResponse>;
}

export function createSchedule(data: ScheduleSaveParams, requestOptions?: RequestOptions) {
	return request({
		url: '/erp/schedule/controller/createSchedule',
		method: 'post',
		data,
		requestOptions,
	});
}

export function updateSchedule(data: ScheduleSaveParams, requestOptions?: RequestOptions) {
	return request({
		url: '/erp/schedule/controller/updateSchedule',
		method: 'put',
		data,
		requestOptions,
	});
}

export function deleteSchedule(params: { id: string }, requestOptions?: RequestOptions) {
	return request({
		url: '/erp/schedule/controller/deleteSchedule',
		method: 'delete',
		params,
		requestOptions,
	});
}
