import {
  AppItem,
  AppList,
  AppParams,
  AppStatsResponse,
  AppStatus,
} from '@/pages/ProjectManagement/data';
import { request } from '@umijs/max';

/** 获取应用列表 GET /api/projects */
export async function queryAppList(params: AppParams) {
  return request<AppList>('/api/projects', {
    method: 'GET',
    params,
  });
}

/** 获取应用统计 GET /api/projects/stats */
export async function queryAppStats() {
  return request<AppStatsResponse>('/api/projects/stats', {
    method: 'GET',
  });
}

/** 新增应用 POST /api/projects */
export async function addApp(data: Partial<AppItem>) {
  return request<AppItem>('/api/projects', {
    method: 'POST',
    data,
  });
}

/** 更新应用 PUT /api/projects/:id */
export async function updateApp(data: Partial<AppItem>) {
  return request<AppItem>(`/api/projects/${data.id}`, {
    method: 'PUT',
    data,
  });
}

/** 更新应用状态 PUT /api/projects/:id/status */
export async function updateAppStatus(id: string, status: AppStatus) {
  return request<AppItem>(`/api/projects/${id}/status`, {
    method: 'PUT',
    data: { status },
  });
}

/** 删除应用 DELETE /api/projects/:id */
export async function removeApp(id: string) {
  return request<{ success: boolean }>(`/api/projects/${id}`, {
    method: 'DELETE',
  });
}
