import { apiClient } from "@/shared/api/axios.instance"; import type { AgentInfo, TokenCreate, TokenUser, LogEntry, LogFilters, InsertLogRequest, InsertLogsRequest, } from "../types/agent.types"; class AgentApiService { private readonly basePath = "/agents"; private readonly authBasePath = "/auth"; private readonly logsBasePath = "/logs"; async getAgents(): Promise { const response = await apiClient.get(this.basePath); return response.data; } async getUsers(): Promise { const response = await apiClient.get(`${this.authBasePath}/tokens`); return response.data; } async createUser(data: TokenCreate): Promise { await apiClient.post(`${this.authBasePath}/token`, data); } async deleteUser(login: string): Promise { await apiClient.delete(`${this.authBasePath}/tokens/${login}`); } async deleteMyAccount(): Promise { await apiClient.delete(`${this.authBasePath}/token`); } async searchLogs(filters?: LogFilters): Promise { const response = await apiClient.get(this.logsBasePath, { params: { level: filters?.level, service: filters?.service, agent: filters?.agent, date_from: filters?.date_from, date_to: filters?.date_to, limit: filters?.limit ?? 100, offset: filters?.offset ?? 0, }, }); return response.data; } async insertLog(entry: InsertLogRequest): Promise { await apiClient.post(this.logsBasePath, entry); } async insertLogsBatch(data: InsertLogsRequest): Promise { await apiClient.post(`${this.logsBasePath}/batch`, data); } async getDistinctAgents(): Promise { const response = await apiClient.get(`${this.logsBasePath}/agents`); return response.data; } async getDistinctLevels(): Promise { const response = await apiClient.get(`${this.logsBasePath}/levels`); return response.data; } async getDistinctServices(): Promise { const response = await apiClient.get(`${this.logsBasePath}/services`); return response.data; } } export const agentApiService = new AgentApiService();