using Netina.Domain.Entities.Warehouses;

namespace Netina.Repository.Handlers.Warehouses;

public class CreateShippingCommandHandler(IRepositoryWrapper repositoryWrapper)
    : IRequestHandler<CreateShippingCommand, ShippingSDto>
{
    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();
    }
}