<?php
/**
 * @author Ulrich Hecht <ulrich.hecht@hecht-software.de>
 * @date 12/16/2016
 */

namespace AppBundle\Validator\Constraints;

use AppBundle\Entity\BookingRequest;
use AppBundle\Entity\TravelDate;
use AppBundle\Entity\TravelProgram;
use AppBundle\Form\BookingRequestType;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;

/**
 * Class BookingRequestValidator
 * @package AppBundle\Validator
 */
class BookingRequestValidator extends ConstraintValidator
{
    /*
    private $travelDate;
    private $travelProgram;

    public function __construct(TravelDate $travelDate, TravelProgram $travelProgram)
    {
        $this->travelDate = $travelDate;
        $this->travelProgram = $travelProgram;
    }
    */

    /**
     * Checks if the passed value is valid.
     *
     * @param BookingRequest $bookingRequest The value that should be validated
     * @param Constraint $constraint The constraint for the validation
     */
    public function validate($bookingRequest, Constraint $constraint)
    {

        for($i = 0; $i < $bookingRequest->getSingleRoomCount(); ++$i)
        {
            $this->context->getValidator()->inContext($this->context)
                ->atPath('rooms['.$i.']')
                ->validate($bookingRequest->getSingleRooms()[$i])
                ;
        }

        for($j = 0; $j < $bookingRequest->getDoubleRoomCount(); ++$j)
        {
            $this->context->getValidator()->inContext($this->context)
                ->atPath('rooms['.($j+5).']')
                ->validate($bookingRequest->getDoubleRooms()[$j])
            ;
        }

        for($k = 0; $k < $bookingRequest->getTripleRoomCount(); ++$k)
        {
            $this->context->getValidator()->inContext($this->context)
                ->atPath('rooms['.($k + 10).']')
                ->validate($bookingRequest->getTripleRooms()[$k])
            ;
        }
    }
}