<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * TravelPeriod
 *
 * @ORM\Table(name="travel_period", indexes={@ORM\Index(name="FK_travel_period_travel_program", columns={"program_id"}), @ORM\Index(name="FK_travel_period_travel_class", columns={"class"}), @ORM\Index(name="FK_travel_period_travel_arrival_point", columns={"travel_arrival_point_id"})})
 * @ORM\Entity(repositoryClass="AppBundle\Entity\TravelPeriodRepository")
 */
class TravelPeriod
{
    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255, nullable=true)
     */
    private $name;

    /**
     * @var boolean
     *
     * @ORM\Column(name="status", type="smallint", nullable=true)
     */
    private $status;

    /**
     * @var integer
     *
     * @ORM\Column(name="order", type="integer", nullable=true)
     */
    private $order;

    /**
     * @var float
     *
     * @ORM\Column(name="price_flight_net", type="float", precision=10, scale=2, nullable=false)
     */
    private $priceFlightNet = '0.00';

    /**
     * @var boolean
     *
     * @ORM\Column(name="is_season", type="boolean", nullable=true)
     */
    private $isSeason = '0';

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var \AppBundle\Entity\TravelArrivalPoint
     *
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\TravelArrivalPoint")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="travel_arrival_point_id", referencedColumnName="id")
     * })
     */
    private $travelArrivalPoint;

    /**
     * @var \AppBundle\Entity\TravelClass
     *
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\TravelClass")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="class", referencedColumnName="id")
     * })
     */
    private $class;

    /**
     * @var \AppBundle\Entity\TravelProgram
     *
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\TravelProgram", inversedBy="periods")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="program_id", referencedColumnName="id")
     * })
     */
    private $program;

    /**
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\TravelPeriodDate", mappedBy="period")
     */
    private $dates;

    /**
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\TravelDeparturePoint", mappedBy="travelPeriod")
     */
    private $departures;

    /**
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\TravelPeriodPrice", mappedBy="period", indexBy="priceType")
     */
    private $prices;

    /**
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\TravelDiscount", mappedBy="period")
     */
    private $discounts;

    /*
     * @ ORM\OneToOne(targetEntity="AppBundle\Entity\FlightPeriod")
     * @ ORM\JoinColumns({
     *   @ ORM\JoinColumn(name="")
     * })
     */
    //private $flightPeriod;

    /**
     * Set name
     *
     * @param string $name
     *
     * @return TravelPeriod
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set status
     *
     * @param integer $status
     *
     * @return TravelPeriod
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * Get status
     *
     * @return integer
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * Set order
     *
     * @param integer $order
     *
     * @return TravelPeriod
     */
    public function setOrder($order)
    {
        $this->order = $order;

        return $this;
    }

    /**
     * Get order
     *
     * @return integer
     */
    public function getOrder()
    {
        return $this->order;
    }

    /**
     * Set priceFlightNet
     *
     * @param float $priceFlightNet
     *
     * @return TravelPeriod
     */
    public function setPriceFlightNet($priceFlightNet)
    {
        $this->priceFlightNet = $priceFlightNet;

        return $this;
    }

    /**
     * Get priceFlightNet
     *
     * @return float
     */
    public function getPriceFlightNet()
    {
        return $this->priceFlightNet;
    }

    /**
     * Set isSeason
     *
     * @param boolean $isSeason
     *
     * @return TravelPeriod
     */
    public function setIsSeason($isSeason)
    {
        $this->isSeason = $isSeason;

        return $this;
    }

    /**
     * Get isSeason
     *
     * @return boolean
     */
    public function getIsSeason()
    {
        return $this->isSeason;
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set travelArrivalPoint
     *
     * @param \AppBundle\Entity\TravelArrivalPoint $travelArrivalPoint
     *
     * @return TravelPeriod
     */
    public function setTravelArrivalPoint(\AppBundle\Entity\TravelArrivalPoint $travelArrivalPoint = null)
    {
        $this->travelArrivalPoint = $travelArrivalPoint;

        return $this;
    }

    /**
     * Get travelArrivalPoint
     *
     * @return \AppBundle\Entity\TravelArrivalPoint
     */
    public function getTravelArrivalPoint()
    {
        return $this->travelArrivalPoint;
    }

    /**
     * Set class
     *
     * @param \AppBundle\Entity\TravelClass $class
     *
     * @return TravelPeriod
     */
    public function setClass(\AppBundle\Entity\TravelClass $class = null)
    {
        $this->class = $class;

        return $this;
    }

    /**
     * Get class
     *
     * @return \AppBundle\Entity\TravelClass
     */
    public function getClass()
    {
        return $this->class;
    }

    /**
     * Set program
     *
     * @param \AppBundle\Entity\TravelProgram $program
     *
     * @return TravelPeriod
     */
    public function setProgram(\AppBundle\Entity\TravelProgram $program = null)
    {
        $this->program = $program;

        return $this;
    }

    /**
     * Get program
     *
     * @return \AppBundle\Entity\TravelProgram
     */
    public function getProgram()
    {
        return $this->program;
    }
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->dates = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Add date
     *
     * @param \AppBundle\Entity\TravelPeriodDate $date
     *
     * @return TravelPeriod
     */
    public function addDate(\AppBundle\Entity\TravelPeriodDate $date)
    {
        $this->dates[] = $date;

        return $this;
    }

    /**
     * Remove date
     *
     * @param \AppBundle\Entity\TravelPeriodDate $date
     */
    public function removeDate(\AppBundle\Entity\TravelPeriodDate $date)
    {
        $this->dates->removeElement($date);
    }

    /**
     * Get dates
     *
     * @return \Doctrine\Common\Collections\Collection|TravelPeriodDate[]
     */
    public function getDates()
    {
        return $this->dates;
    }

    /**
     * Add departure
     *
     * @param \AppBundle\Entity\TravelDeparturePoint $departure
     *
     * @return TravelPeriod
     */
    public function addDeparture(\AppBundle\Entity\TravelDeparturePoint $departure)
    {
        $this->departures[] = $departure;

        return $this;
    }

    /**
     * Remove departure
     *
     * @param \AppBundle\Entity\TravelDeparturePoint $departure
     */
    public function removeDeparture(\AppBundle\Entity\TravelDeparturePoint $departure)
    {
        $this->departures->removeElement($departure);
    }

    /**
     * Get departures
     *
     * @return \Doctrine\Common\Collections\Collection|TravelDeparturePoint[]
     */
    public function getDepartures()
    {
        return $this->departures;
    }

    /**
     * Add price
     *
     * @param \AppBundle\Entity\TravelPeriodPrice $price
     *
     * @return TravelPeriod
     */
    public function addPrice(\AppBundle\Entity\TravelPeriodPrice $price)
    {
        $this->prices[] = $price;

        return $this;
    }

    /**
     * Remove price
     *
     * @param \AppBundle\Entity\TravelPeriodPrice $price
     */
    public function removePrice(\AppBundle\Entity\TravelPeriodPrice $price)
    {
        $this->prices->removeElement($price);
    }

    /**
     * Get prices
     *
     * @return \Doctrine\Common\Collections\Collection|TravelPeriodPrice[]
     */
    public function getPrices()
    {
        return $this->prices;
    }

    /**
     * Add discount
     *
     * @param \AppBundle\Entity\TravelDiscount $discount
     *
     * @return TravelPeriod
     */
    public function addDiscount(\AppBundle\Entity\TravelDiscount $discount)
    {
        $this->discounts[] = $discount;

        return $this;
    }

    /**
     * Remove discount
     *
     * @param \AppBundle\Entity\TravelDiscount $discount
     */
    public function removeDiscount(\AppBundle\Entity\TravelDiscount $discount)
    {
        $this->discounts->removeElement($discount);
    }

    /**
     * Get discounts
     *
     * @return \Doctrine\Common\Collections\Collection|TravelDiscount[]
     */
    public function getDiscounts()
    {
        return $this->discounts;
    }

    /**
     * @return \DateTime
     * @throws \Exception
     */
    public function getStartDate()
    {
        if ($this->isSeason)
        {
            throw new \Exception('Call to getStartDate() is only allowed for non-seasons');
        }
        return $this->getDates()->first()->getStartDate();
    }

    /**
     * @return \DateTime
     * @throws \Exception
     */
    public function getEndDate()
    {
        if ($this->isSeason)
        {
            throw new \Exception('Call to getEndDate() is only allowed for non-seasons');
        }
        return $this->getDates()->first()->getEndDate();
    }
}
