using System.Net.Http; using System.Net.Http.Json; using EngineeringSync.Domain.Entities; namespace EngineeringSync.TrayApp.Services; public class ApiClient(HttpClient http) { private const string Base = "http://localhost:5050/api"; public Task?> GetProjectsAsync() => http.GetFromJsonAsync>($"{Base}/projects"); public Task?> GetChangesAsync(Guid projectId) => http.GetFromJsonAsync>($"{Base}/changes/{projectId}"); public Task?> ScanFoldersAsync(string engineeringPath, string simulationPath, string fileExtensions) => http.GetFromJsonAsync>($"{Base}/projects/scan?engineeringPath={Uri.EscapeDataString(engineeringPath)}&simulationPath={Uri.EscapeDataString(simulationPath)}&fileExtensions={Uri.EscapeDataString(fileExtensions)}"); public async Task CreateProjectAsync(CreateProjectDto dto) { var resp = await http.PostAsJsonAsync($"{Base}/projects", dto); resp.EnsureSuccessStatusCode(); } public async Task UpdateProjectAsync(Guid id, UpdateProjectDto dto) { var resp = await http.PutAsJsonAsync($"{Base}/projects/{id}", dto); resp.EnsureSuccessStatusCode(); } public async Task DeleteProjectAsync(Guid id) { var resp = await http.DeleteAsync($"{Base}/projects/{id}"); resp.EnsureSuccessStatusCode(); } public async Task SyncChangesAsync(List ids) { var resp = await http.PostAsJsonAsync($"{Base}/sync", new { ChangeIds = ids }); resp.EnsureSuccessStatusCode(); } public async Task IgnoreChangesAsync(List ids) { var resp = await http.PostAsJsonAsync($"{Base}/ignore", new { ChangeIds = ids }); resp.EnsureSuccessStatusCode(); } } public record CreateProjectDto(string Name, string EngineeringPath, string SimulationPath, string FileExtensions, bool IsActive = true, bool BackupEnabled = true, string? BackupPath = null, int MaxBackupsPerFile = 0); public record UpdateProjectDto(string Name, string EngineeringPath, string SimulationPath, string FileExtensions, bool IsActive, bool BackupEnabled = true, string? BackupPath = null, int MaxBackupsPerFile = 0); public record ScanResultDto(string RelativePath, string ChangeType, long Size, DateTime LastModified);