using Netina.Domain.Entities.Warehouses;

namespace Netina.Repository.Handlers.Warehouses;

public class CreateShippingCommandHandler : IRequestHandler<CreateShippingCommand , ShippingSDto>
{
    private readonly IRepositoryWrapper _repositoryWrapper;

    public CreateShippingCommandHandler(IRepositoryWrapper repositoryWrapper)
    {
        _repositoryWrapper = repositoryWrapper;
    }
    public async Task<ShippingSDto> Handle(CreateShippingCommand request, CancellationToken cancellationToken)
    {
        var ent = Shipping.Create(request.Name, request.WarehouseName, request.IsExpressShipping, request.IsShipBySeller,
            request.IsOriginalWarehouse,request.DeliveryCost,request.WorkingDays);
        _repositoryWrapper.SetRepository<Shipping>().Add(ent);
        await _repositoryWrapper.SaveChangesAsync(cancellationToken);
        return ent.AdaptToSDto();
    }
}