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

const BASE_URL = '/api/v1/repository-manager';

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

// 获取 Git 实例信息
export const getGitInstanceInfo = (externalSystemId: number) =>
    request.get<GitInstanceInfo>(`${BASE_URL}/${externalSystemId}/instance`);

// 同步所有 Git 数据
export const syncAllGitData = (externalSystemId: number) =>
    request.post<void>(`${BASE_URL}/${externalSystemId}/sync-all`);

// 同步 Git 仓库组
export const syncGitGroups = (externalSystemId: number) =>
    request.post<void>(`${BASE_URL}/${externalSystemId}/sync-groups`);

// 同步 Git 项目
export const syncGitProjects = (externalSystemId: number) =>
    request.post<void>(`${BASE_URL}/${externalSystemId}/groups/sync-projects`);

// 同步 Git 分支
export const syncGitBranches = (externalSystemId: number) =>
    request.post<void>(`${BASE_URL}/${externalSystemId}/projects/sync-branches`);
