import request from '@/utils/request';
import type { JenkinsInstance, JenkinsInstanceDTO } from './types';
import { getExternalSystems } from '@/pages/Deploy/External/service';
import { SystemType } from '@/pages/Deploy/External/types';

// 获取 Jenkins 实例列表
export const getJenkinsInstances = () => 
  getExternalSystems({
    type: SystemType.JENKINS,
    enabled: true
  }).then(response => response.content);

// 获取 Jenkins 实例详情
export const getJenkinsInstance = (externalSystemId: string) =>
  request.get<JenkinsInstanceDTO>(`/api/v1/jenkins-manager/${externalSystemId}/instance`);

// 同步视图
export const syncViews = (externalSystemId: string) =>
  request.post<void>(`/api/v1/jenkins-manager/${externalSystemId}/sync-views`);

// 同步任务
export const syncJobs = (externalSystemId: string) =>
  request.post<void>(`/api/v1/jenkins-manager/${externalSystemId}/sync-jobs`);

// 同步构建
export const syncBuilds = (externalSystemId: string) =>
  request.post<void>(`/api/v1/jenkins-manager/${externalSystemId}/sync-builds`);
