public ITrolleyCalculationService GetTrolleyCalculator(TrolleyCalculatorType calculatorType)
        {
            switch (calculatorType)
            {
            case TrolleyCalculatorType.Local:
                return(_provider.GetRequiredService <LocalTrolleyCalculationService>());

            default:
                return(_provider.GetRequiredService <RemoteTrolleyCalculationService>());
            }
        }
        public CalculateTrolleyTotalCommand(RequestTrolley trolley, TrolleyCalculatorType calculatorType)
        {
            if (trolley == null)
            {
                throw new ArgumentNullException(nameof(trolley));
            }

            if (trolley.Products == null)
            {
                throw new ArgumentNullException(nameof(trolley.Products));
            }

            if (trolley.Quantities == null)
            {
                throw new ArgumentNullException(nameof(trolley.Quantities));
            }

            if (trolley.Quantities.Select(x => x.Name).Except(trolley.Products.Select(x => x.Name)).Any())
            {
                throw new InvalidTrolleyStateException("Products and Quantities are out of sync");
            }

            if (trolley.Specials != null &&
                trolley.Specials.Any() &&
                trolley.Specials.SelectMany(x => x.Quantities.Select(q => q.Name))
                .Except(trolley.Products.Select(x => x.Name)).Any())
            {
                throw new InvalidTrolleyStateException("Products and Specials are out of sync");
            }

            if (trolley.Quantities.Any(x => x.Quantity <= 0))
            {
                throw new InvalidTrolleyStateException("Quantities cannot be negative");
            }

            Trolley = trolley;

            TrolleyCalculatorType = calculatorType;
        }