using Common.Dtos.Conversation; using Common.Enums; using System.Net.Http.Json; namespace HushianWebApp.Service { public class ChatService { private readonly BaseController _baseController; const string BaseRoute = "v1/Chat/"; public ChatService(BaseController baseController) { _baseController = baseController; } //Inbox1 public async Task> ChatAwaitingOurResponse() { var response = await _baseController.Get($"{BaseRoute}ChatsAwaitingOurResponse"); if (response.IsSuccessStatusCode) return await response.Content.ReadFromJsonAsync>(); return new(); } //Inbox2 public async Task> MyChatsIsInProgress() { var response = await _baseController.Post($"{BaseRoute}MyChats", ConversationStatus.InProgress); if (response.IsSuccessStatusCode) return await response.Content.ReadFromJsonAsync>(); return new(); } //Inbox3 public async Task> MyChatsIsFinished() { var response = await _baseController.Post($"{BaseRoute}MyChats", ConversationStatus.Finished); if (response.IsSuccessStatusCode) return await response.Content.ReadFromJsonAsync>(); return new(); } public async Task NewChatFromCurrentUser(ADD_ConversationDto conversation) { var response = await _baseController.Post($"{BaseRoute}NewChatFromCurrentUser", conversation); if (response.IsSuccessStatusCode) return await response.Content.ReadFromJsonAsync(); return null; } public async Task ADDChatResponse(int ConversationID, string text, ConversationType type) { var response = await _baseController.Post($"{BaseRoute}ADDChatResponse", new ADD_ConversationResponseDto() { ConversationID = ConversationID, Text = text, Type = type }); if (response.IsSuccessStatusCode) return await response.Content.ReadFromJsonAsync(); return null; } // Send chat response with optional file attachment (e.g., image) public async Task ADDChatResponse(int conversationID, string text, ConversationType type, string? fileName, string? fileType, byte[]? fileContent) { if (text == null) text = ""; var response = await _baseController.Post($"{BaseRoute}ADDChatResponse", new ADD_ConversationResponseDto() { ConversationID = conversationID, Text = text, Type = type, FileName = fileName, FileType = fileType, FileContent = fileContent }); if (response.IsSuccessStatusCode) return await response.Content.ReadFromJsonAsync(); return null; } public async Task OpenChat(int ChatID) { var response = await _baseController.Put($"{BaseRoute}OpenChat/{ChatID}"); return response.IsSuccessStatusCode; } public async Task ChatIsFinish(int ChatID) { var response = await _baseController.Put($"{BaseRoute}ChatIsFinish/{ChatID}"); return response.IsSuccessStatusCode; } public async Task Attachedto(int toExperID, int ChatID) { var response = await _baseController.Put($"{BaseRoute}Attached-to/{toExperID}/{ChatID}"); return response.IsSuccessStatusCode; } public async Task ChatIsFinishFromUser(int ChatID) { var response = await _baseController.Put($"{BaseRoute}ChatIsFinishFromUser/{ChatID}"); return response.IsSuccessStatusCode; } public async Task MarkAsReadChatItemAsync(int ID) { var response = await _baseController.Put($"{BaseRoute}MarkAsReadChatItem/{ID}"); return response.IsSuccessStatusCode; } public async Task GetLastOpenChatInCompany(int CompanyID) { var response = await _baseController.Get($"{BaseRoute}User/LastOpenChatInCompany/{CompanyID}"); if (response.StatusCode==System.Net.HttpStatusCode.OK) return await response.Content.ReadFromJsonAsync(); return null; } public async Task Getchat(int ChatID) { var response = await _baseController.Get($"{BaseRoute}User/Chat/{ChatID}"); if (response.StatusCode == System.Net.HttpStatusCode.OK) return await response.Content.ReadFromJsonAsync(); return null; } } }