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

// 平台查询参数
export interface DatasourcePlatformQueryParams {
	keyword?: string;
	status?: string;
	pageNum: number;
	pageSize: number;
}

// 创建平台参数
export interface CreateDatasourcePlatformParams {
	platformCode: string;
	platformName: string;
	description?: string;
	apiBaseUrl: string;
	authType: string;
	status?: string;
	token?: string;
	apiKey?: string;
	clientId?: string;
	clientSecret?: string;
	rateLimitPerMinute?: number;
	rateLimitPerHour?: number;
	concurrencyLimit?: number;
	requestTimeoutMs?: number;
	maxRetries?: number;
	retryDelayMs?: number;
	authConfig?: Record<string, any>;
}

// 更新平台参数
export interface UpdateDatasourcePlatformParams extends Partial<CreateDatasourcePlatformParams> {
	id: string;
	version?: string;
}

// 更新平台状态参数
export interface UpdateDatasourcePlatformStatusParams {
	id: string;
	Status: string;
}

// 平台信息
export interface DatasourcePlatformInfo {
	id: string;
	platformCode: string;
	platformName: string;
	description?: string;
	status: string;
	statusName: string;
	apiBaseUrl: string;
	authType: string;
	authTypeName: string;
	token?: string;
	apiKey?: string;
	clientId?: string;
	clientSecret?: string;
	authConfig?: Record<string, any>;
	rateLimitPerMinute?: number;
	rateLimitPerHour?: number;
	concurrencyLimit?: number;
	requestTimeoutMs?: number;
	maxRetries?: number;
	retryDelayMs?: number;
	createdAt?: number;
	updatedAt?: number;
}

// 获取平台列表
export function listDatasourcePlatforms(params: DatasourcePlatformQueryParams) {
	return request({
		url: '/data-engine/datasource/platform/controller/listDatasourcePlatforms',
		method: 'get',
		params,
	});
}

// 创建平台
export function createDatasourcePlatform(data: CreateDatasourcePlatformParams) {
	return request({
		url: '/data-engine/datasource/platform/controller/createDatasourcePlatform',
		method: 'post',
		data,
	});
}

// 更新平台
export function updateDatasourcePlatform(data: UpdateDatasourcePlatformParams) {
	return request({
		url: '/data-engine/datasource/platform/controller/updateDatasourcePlatform',
		method: 'put',
		data,
	});
}

// 删除平台
export function deleteDatasourcePlatform(id: string) {
	return request({
		url: '/data-engine/datasource/platform/controller/deleteDatasourcePlatform',
		method: 'delete',
		params: { id },
	});
}

// 获取平台详情
export function getDatasourcePlatform(id: string) {
	return request({
		url: '/data-engine/datasource/platform/controller/getDatasourcePlatform',
		method: 'get',
		params: { id },
	});
}

// 根据编码获取平台信息
export function getPlatformByCode(platformCode: string) {
	return request({
		url: '/data-engine/datasource/platform/controller/getPlatformByCode',
		method: 'get',
		params: { platformCode },
	});
}

// 更新平台状态
export function updateDatasourcePlatformStatus(data: UpdateDatasourcePlatformStatusParams) {
	return request({
		url: '/data-engine/datasource/platform/controller/updateDatasourcePlatformStatus',
		method: 'put',
		data,
	});
}
