using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BookingModule.Entity;
using BookingModule.Exceptions;

namespace BookingModule.Validation
{
    public static class BookingValidationManager
    {
        /// <summary>
        /// Validate the request object
        /// </summary>
        /// <param name="request">Request object from the client</param>
        public static void ValidateAvailabilityRequest(AvailabilityRequest request)
        {
            if (string.IsNullOrEmpty(request.Origin))
            {
                throw new BookingException(Resources.ValidationMessages.EmptyOrigin, BookingFault.Validation);
            }

            if (string.IsNullOrEmpty(request.Destination))
            {
                throw new BookingException(Resources.ValidationMessages.EmptyDestination, BookingFault.Validation);
            }

            if (request.Origin == request.Destination)
            {
                throw new BookingException(Resources.ValidationMessages.OriginDestinatioMissmatch, BookingFault.Validation);
            }

            if (request.DepartureDate == null)
            {
                throw new BookingException(Resources.ValidationMessages.EmptyDepartureDate, BookingFault.Validation);
            }

            if (request.ReturnDate == null)
            {
                throw new BookingException(Resources.ValidationMessages.EmptyReturnDate, BookingFault.Validation);
            }

            if (request.DepartureDate > request.ReturnDate)
            {
                throw new BookingException(Resources.ValidationMessages.WrongDateRange, BookingFault.Validation);
            }
        }
    }
}
