import request from '@/utils/request';
import type { Page } from '@/types/base/page';
import type { ExternalSystemResponse, ExternalSystemRequest, ExternalSystemQuery } from './types';

const BASE_URL = '/api/v1/external-system';

// 获取三方系统列表
export const getExternalSystemsPage = (params: ExternalSystemQuery) =>
    request.get<Page<ExternalSystemResponse>>(`${BASE_URL}/page`, { params });

export const getExternalSystems = (params: ExternalSystemQuery) =>
    request.get<Page<ExternalSystemResponse>>(`${BASE_URL}/page`, { params });

// 创建三方系统
export const createExternalSystem = (data: ExternalSystemRequest) =>
    request.post<ExternalSystemResponse>(BASE_URL, data);

// 更新三方系统
export const updateExternalSystem = (id: number, data: ExternalSystemRequest) =>
    request.put<ExternalSystemResponse>(`${BASE_URL}/${id}`, data);

// 删除三方系统
export const deleteExternalSystem = (id: number) =>
    request.delete(`${BASE_URL}/${id}`);

// 测试连接
export const testConnection = (id: number) =>
    request.get<boolean>(`${BASE_URL}/${id}/test-connection`);

// 更新状态
export const updateStatus = (id: number, enabled: boolean) =>
    request.put(`${BASE_URL}/${id}/status`, null, { params: { enabled } }); 