using System.Collections.Concurrent; using AyCode.Blazor.Components.Services; using AyCode.Core; using AyCode.Core.Extensions; using AyCode.Core.Helpers; using AyCode.Core.Interfaces; using AyCode.Interfaces.Entities; using AyCode.Services.Loggers; using AyCode.Services.SignalRs; using MessagePack.Resolvers; using Microsoft.AspNetCore.SignalR.Client; using TIAM.Core.Consts; using TIAM.Entities.Drivers; using TIAM.Entities.Transfers; using TIAM.Entities.Users; using TIAM.Models.Dtos.Users; using TIAM.Services; using TIAM.Services.Interfaces; using TIAMWebApp.Shared.Application.Models.ClientSide; using TIAMWebApp.Shared.Application.Utility; namespace TIAMWebApp.Shared.Application.Services { public class AdminSignalRClient : AcSignalRClientBase, IUserApiControllerClient, ITransferApiControllerClient { public AdminSignalRClient(IEnumerable logWriters) : base($"{Setting.BaseUrl}/DevAdminHub", new LoggerClient(nameof(AdminSignalRClient), logWriters.ToArray())) { ConstHelper.NameByValue(0); } #region IUserApiController public async Task UpdateUser(User user) => await PostDataAsync(SignalRTags.UpdateUser, user); public async Task UpdateUserModelDtoDetail(UserModelDtoDetail userModelDtoDetail) => await PostDataAsync(SignalRTags.UpdateUserModelDtoDetail, userModelDtoDetail); #endregion IUserApiController #region ICompanyApiController public async Task> GetAllCarsByProductId(Guid productId) { Logger.Detail($"GetAllCarsByProductId client called; productId: {productId}"); return await GetAllAsync>(SignalRTags.GetAllCarsByProductId, [productId]) ?? []; } public Task GetAllCarsAndDriversByProductIdAsync(Guid productId, List intoCars, List intoDrivers, Action? callback = null) { return GetAllCarsByProductIdAsync(productId, intoCars, () => { intoDrivers.Clear(); intoDrivers.AddRange(intoCars.DistinctBy(x => x.UserProductMappingId).Select(x => x.UserProductMapping)); callback?.Invoke(); }); } public Task GetAllCarsByProductIdAsync(Guid productId, List intoCars, Action? callback = null) { Logger.Detail($"GetAllCarsByProductIdAsync client called; productId: {productId}"); //TODO: AdminSignalRClient.GetAllIntoAsync(_cars, SignalRTags.GetAllCarsByProductId, [productId]) - J. return GetAllAsync>(SignalRTags.GetAllCarsByProductId, response => { if (response is { Status: SignalResponseStatus.Success, ResponseData: not null }) { intoCars.Clear(); intoCars.AddRange(response.ResponseData); } callback?.Invoke(); return Task.CompletedTask; }, [productId]); } #endregion ICompanyApiController #region ITransferApiController public async Task> GetTransfers() => await GetAllAsync>(SignalRTags.GetTransfers) ?? []; public async Task> GetTransfersByFilterText(string criteriaOperatorText) => await GetAllAsync>(SignalRTags.GetTransfersByFilterText, [criteriaOperatorText]) ?? []; public async Task> GetTransfersByUserId(Guid userId) => await GetAllAsync>(SignalRTags.GetTransfersByUserId, [userId]) ?? []; public async Task GetTransfersByDriverId(Guid userProductMappingId) { throw new NotImplementedException(); } public async Task GetTransferById(Guid transferId) => await GetByIdAsync(SignalRTags.GetTransfer, transferId); public async Task UpdateTransfer(Transfer transfer) { throw new NotImplementedException(); } public async Task RemoveTransfer(Transfer transfer) { throw new NotImplementedException(); } public async Task> GetAllDrivers() { throw new NotImplementedException(); } public async Task> GetAllDriversByProductId(Guid productId) { throw new NotImplementedException(); } public async Task GetTransferDriver(Guid transferDriverId) { throw new NotImplementedException(); } public async Task> GetTransferDrivers(Guid transferId) { throw new NotImplementedException(); } public async Task AddTransferDriver(TransferToDriver transferToDriver) { throw new NotImplementedException(); } public async Task UpdateTransferDriver(TransferToDriver transferToDriver) { throw new NotImplementedException(); } public async Task RemoveTransferDriver(TransferToDriver transferToDriver) { throw new NotImplementedException(); } public List GetTransferDestinations() { throw new NotImplementedException(); } public async Task GetTransferDestinationById(Guid transferDestinationId) { throw new NotImplementedException(); } public async Task CreateTransferDestination(TransferDestination transferDestination) { throw new NotImplementedException(); } public async Task UpdateTransferDestination(TransferDestination transferDestination) { throw new NotImplementedException(); } public async Task RemoveTransferDestination(TransferDestination transferDestination) { throw new NotImplementedException(); } public async Task> GetAllTransferDestinationToProducts() { throw new NotImplementedException(); } public async Task> GetTransferDestinationToProductsByProductId(Guid productId) { throw new NotImplementedException(); } public async Task> GetTransferDestinationToProductsByTransferDestinationId(Guid transferDestinationId) { throw new NotImplementedException(); } public async Task GetTransferDestinationToProductById(Guid transferDestinationToProductId) { throw new NotImplementedException(); } public async Task CreateTransferDestinationToProduct(TransferDestinationToProduct transferDestinationToProduct) { throw new NotImplementedException(); } public async Task UpdateTransferDestinationToProduct(TransferDestinationToProduct transferDestinationToProduct) { throw new NotImplementedException(); } public async Task RemoveTransferDestinationToProduct(TransferDestinationToProduct transferDestinationToProduct) { throw new NotImplementedException(); } #endregion ITransferApiController } }