import { apiClient } from "./client"; export type ComposeFile = "docker-compose.yml" | "docker-compose.dev.yml"; export type DeploymentStatus = "idle" | "running" | "success" | "failed"; export type DeploymentEnv = "dev" | "prod"; export interface DeploymentProject { _id: string; name: string; rootPath: string; repoUrl: string; branch: string; composeFile: ComposeFile; webhookToken: string; env: DeploymentEnv; port?: number; lastDeployAt?: string; lastStatus: DeploymentStatus; lastMessage?: string; createdAt: string; updatedAt: string; } export interface DeploymentRun { _id: string; project: string; status: "running" | "success" | "failed"; message?: string; logs: string[]; startedAt: string; finishedAt?: string; durationMs?: number; createdAt: string; updatedAt: string; } export interface DeploymentRunWithProject extends Omit { project: DeploymentProject; } export interface DeploymentDetailResponse { project: DeploymentProject; runs: DeploymentRun[]; } export interface DeploymentMetrics { dailyStats: Array<{ _id: string; total: number; success: number; failed: number; avgDurationMs?: number; }>; recentRuns: DeploymentRunWithProject[]; } export interface DeploymentCandidate { name: string; rootPath: string; composeFiles: ComposeFile[]; } export interface DeploymentInput { name: string; rootPath: string; repoUrl: string; branch: string; composeFile: ComposeFile; port?: number; } export async function fetchDeployments(): Promise { const { data } = await apiClient.get("/deployments"); return data as DeploymentProject[]; } export async function fetchDeploymentBranches(repoUrl: string): Promise { const { data } = await apiClient.get("/deployments/branches", { params: { repoUrl } }); return (data as { branches: string[] }).branches; } export async function scanDeployments(): Promise { const { data } = await apiClient.get("/deployments/scan"); return data as DeploymentCandidate[]; } export async function createDeployment(payload: DeploymentInput): Promise { const { data } = await apiClient.post("/deployments", payload); return data as DeploymentProject; } export async function updateDeployment(id: string, payload: Omit) { const { data } = await apiClient.put(`/deployments/${id}`, payload); return data as DeploymentProject; } export async function deleteDeployment(id: string): Promise { await apiClient.delete(`/deployments/${id}`); } export async function runDeployment(id: string): Promise { await apiClient.post(`/deployments/${id}/run`); } export async function fetchDeployment(id: string): Promise { const { data } = await apiClient.get(`/deployments/${id}`); return data as DeploymentDetailResponse; } export async function fetchDeploymentMetrics(): Promise { const { data } = await apiClient.get("/deployments/metrics/summary"); return data as DeploymentMetrics; }