using AyCode.Core.Loggers;
using AyCode.Services.Server.SignalRs;
using FruitBank.Common.Dtos;
using FruitBank.Common.Entities;
using FruitBank.Common.Models.SignalRs;
using FruitBank.Common.SignalRs;
using Mango.Nop.Core.Loggers;
using Microsoft.AspNetCore.SignalR;
using Nop.Core.Domain.Orders;

namespace FruitBank.Common.Server.Services.SignalRs;

public class SignalRSendToClientService(IHubContext<DevAdminSignalRHub, IAcSignalRHubItemServer> signalRHub, IEnumerable<IAcLogWriterBase> logWriters) 
    : AcSignalRSendToClientService<DevAdminSignalRHub, SignalRTags, Logger>(signalRHub, new Logger<SignalRSendToClientService>(logWriters.ToArray()))
{
    public Task SendMeasuringNotification(string message) => SendMeasuringNotification(message, null);
    public Task SendMeasuringNotification(OrderDto orderDto) => SendMeasuringNotification(null, orderDto);

    public Task SendMeasuringNotification(string? message, OrderDto? orderDto)
    {
        var notificationMessage = new SignalRMessageToClientWithText<OrderDto>(message, orderDto);
        return base.SendMessageToAllClients(SignalRTags.NotificationReceived, notificationMessage);
    }

    public Task SendProductChanged(ProductDto productDto) => base.SendMessageToAllClients(SignalRTags.SendProductChanged, productDto);

    public Task SendOrderChanged(OrderDto orderDto) => base.SendMessageToAllClients(SignalRTags.SendOrderChanged, orderDto);
    public Task SendOrderItemChanged(OrderItemDto orderItemDto) => base.SendMessageToAllClients(SignalRTags.SendOrderItemChanged, orderItemDto);
    public Task SendOrderItemDeleted(OrderItem orderItem) => base.SendMessageToAllClients(SignalRTags.SendOrderItemDeleted, orderItem);
    public Task SendOrderItemPalletChanged(OrderItemPallet orderItemPallet) => base.SendMessageToAllClients(SignalRTags.SendOrderItemPalletChanged, orderItemPallet);

    public Task SendShippingChanged(Shipping shipping) => base.SendMessageToAllClients(SignalRTags.SendShippingChanged, shipping);
    public Task SendShippingItemChanged(ShippingItem shippingItem) => base.SendMessageToAllClients(SignalRTags.SendShippingItemChanged, shippingItem);
    public Task SendShippingDocumentChanged(ShippingDocument shippingDocument) => base.SendMessageToAllClients(SignalRTags.SendShippingDocumentChanged, shippingDocument);
    public Task SendShippingItemPalletChanged(ShippingItemPallet shippingItemPallet) => base.SendMessageToAllClients(SignalRTags.SendShippingItemPalletChanged, shippingItemPallet);
}