import request from '/@/utils/request';

// 接口查询参数
export interface ApiInterfaceQueryParams {
	keyword?: string;
	platformId?: string;
	status?: string;
	method?: string;
	pageNum: number;
	pageSize: number;
}

// 创建接口参数
export interface CreateApiInterfaceParams {
	platformId: string | number;
	name: string;
	code: string;
	url: string;
	method: string;
	status?: string;
	authType?: string;
	requestConfig?: Record<string, any>;
	responseConfig?: Record<string, any>;
	limitConfig?: Record<string, any>;
}

// 更新接口参数
export interface UpdateApiInterfaceParams extends Partial<CreateApiInterfaceParams> {
	id: string;
}

// 更新接口状态参数
export interface UpdateApiInterfaceStatusParams {
	id: string;
	status: string;
}

// 接口信息（响应字段）
export interface ApiInterfaceInfo {
	id: string;
	platformId: string | number;
	platformName?: string;
	name: string;
	code: string;
	url: string;
	method: string;
	status: string;
	statusName?: string;
	authType?: string;
	requestConfig?: Record<string, any>;
	responseConfig?: Record<string, any>;
	limitConfig?: Record<string, any>;
	createdBy?: string;
	createdAt?: number;
	updatedBy?: string;
	updatedAt?: number;
}

// 获取接口列表
export function listApiInterfaces(params: ApiInterfaceQueryParams) {
	return request({
		url: '/api/interface/controller/listApiInterfaces',
		method: 'get',
		params,
	});
}

// 获取接口详情
export function getApiInterface(id: string) {
	return request({
		url: '/api/interface/controller/getApiInterface',
		method: 'get',
		params: { id },
	});
}

// 创建接口
export function createApiInterface(data: CreateApiInterfaceParams) {
	return request({
		url: '/api/interface/controller/createApiInterface',
		method: 'post',
		data,
	});
}

// 修改接口
export function updateApiInterface(data: UpdateApiInterfaceParams) {
	return request({
		url: '/api/interface/controller/updateApiInterface',
		method: 'put',
		data,
	});
}

// 更新接口状态
export function updateApiInterfaceStatus(data: UpdateApiInterfaceStatusParams) {
	return request({
		url: '/api/interface/controller/updateApiInterfaceStatus',
		method: 'put',
		data,
	});
}

// 删除接口
export function deleteApiInterface(id: string) {
	return request({
		url: '/api/interface/controller/deleteApiInterface',
		method: 'delete',
		params: { id },
	});
}
