public bool CanRentAtPeriod(DatePeriod period)
        {
            foreach (var rent in _rents)
            {
                if (rent.Period.IntersectsWith(period))
                {
                    return(false);
                }
            }

            return(true);
        }
        public Rent Rent(DatePeriod period)
        {
            if (!IsAvailableOnPeriod(period))
            {
                throw new InvalidOperationException(
                          $"Car {Id} is unavailable to rent on choisen period");
            }

            var rent = new Rent(Guid.NewGuid(), Id, period);

            _rents.Add(rent);

            ScheduleMaintenanceIfNeeded();

            return(rent);
        }
        public bool IsAvailableOnPeriod(DatePeriod period)
        {
            foreach (var rent in _rents)
            {
                if (rent.Period.IntersectsWith(period))
                {
                    return(false);
                }
            }

            foreach (var maintenance in _maintenances)
            {
                if (maintenance.IntersectsWith(period))
                {
                    return(false);
                }
            }

            return(true);
        }
 public bool IntersectsWith(DatePeriod anotherPeriod)
 {
     return(!(Start > anotherPeriod.End || End < anotherPeriod.Start));
 }
 public Rent(Guid id, Guid carId, DatePeriod period)
 {
     Id     = id;
     CarId  = carId;
     Period = period ?? throw new ArgumentNullException(nameof(period));
 }