<?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)
    {

        /*var_dump($bookingRequest->getSingleRoomCount());
        echo "<br>-<br>";
        $bs = $bookingRequest->getSingleRooms();
        foreach ($bs as $b ){
            var_dump($b->getCount());
            echo "<br>";
            var_dump($b->getTravelerCount());
            echo "<br>-<br>";
        }*/
        /*

        for($i = 0; $i < $bookingRequest->getSingleRoomCount(); ++$i)
        {
            //echo "<br>check 1<br>";
            $a = $bookingRequest->getSingleRooms()[$i];
            var_dump($a->getCount());
            var_dump($i);

            $this->context->getValidator()->inContext($this->context)
                ->atPath('rooms['.$i.']')
                ->validate($bookingRequest->getSingleRooms()[$i])
                ;
        }

        for($i = 1; $i < $bookingRequest->getSingleRoomChildCount(); ++$i)
        {
            //echo "<br>check 2<br>";
            $a = $bookingRequest->getSingleChildRooms()[$i];
            //var_dump($a->getType());
            $this->context->getValidator()->inContext($this->context)
                ->atPath('rooms['.($i+3).']')
                ->validate($bookingRequest->getSingleChildRooms()[$i])
            ;
        }
        for($i = 1; $i < $bookingRequest->getDoubleRoomCount(); ++$i)
        {
            //echo "<br>check 3<br>";
            $this->context->getValidator()->inContext($this->context)
                ->atPath('rooms['.($i+7).']')
                ->validate($bookingRequest->getDoubleRooms()[$i])
            ;
        }

        for($i = 1; $i < $bookingRequest->getDoubleRoomChildCount(); ++$i)
        {
            //echo "<br>check 4<br>";
            $this->context->getValidator()->inContext($this->context)
                ->atPath('rooms['.($i+10).']')
                ->validate($bookingRequest->getDoubleChildRooms()[$i])
            ;
        }
        for($i = 1; $i < $bookingRequest->getTripleRoomCount(); ++$i)
        {
            //echo "<br>check 5<br>";
            $this->context->getValidator()->inContext($this->context)
                ->atPath('rooms['.($i + 13).']')
                ->validate($bookingRequest->getTripleRooms()[$i])
            ;
        }
        for($i = 1; $i < $bookingRequest->getTripleRoomChildCount(); ++$i)
        {
            //echo "<br>check 6<br>";
            $this->context->getValidator()->inContext($this->context)
                ->atPath('rooms['.($i + 15).']')
                ->validate($bookingRequest->getTripleChildRooms()[$i])
            ;
        }

        die();
        */

    }
}