<?php

namespace KupShop\OrderingBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use KupShop\I18nBundle\Entity\Currency;

/**
 * DeliveryType.
 *
 * @ORM\Table(name="delivery_type", indexes={
 *
 *     @ORM\Index(name="id_delivery", columns={"id_delivery"}),
 *      @ORM\Index(name="id_payment", columns={"id_payment"})
 * })
 *
 * @ORM\Entity
 */
class DeliveryType
{
    public function getId(): int
    {
        return $this->id;
    }

    public function setId(int $id)
    {
        $this->id = $id;
    }

    public function isListOrder(): bool
    {
        return $this->listOrder;
    }

    public function setListOrder(bool $listOrder)
    {
        $this->listOrder = $listOrder;
    }

    /**
     * @return \Decimal
     */
    public function getPrice(): string
    {
        if (!$this->price) {
            $deliveryTypePrice = \DecimalConstants::zero();

            if ($this->getIdDelivery()) {
                $deliveryPrice = $this->getIdDelivery()->getPrice();
                $deliveryTypePrice = $deliveryTypePrice->add(toDecimal($deliveryPrice));
            }

            if ($this->getIdPayment()) {
                $paymentPrice = $this->getIdPayment()->getPrice();
                $deliveryTypePrice = $deliveryTypePrice->add(toDecimal($paymentPrice));
            }

            return $deliveryTypePrice;
        }

        return $this->price;
    }

    public function setPrice(string $price)
    {
        $this->price = $price;
    }

    public function getCurrency(): Currency
    {
        return $this->currency;
    }

    public function setCurrency(Currency $currency)
    {
        $this->currency = $currency;
    }

    public function isVat(): bool
    {
        return $this->vat;
    }

    public function setVat(bool $vat)
    {
        $this->vat = $vat;
    }

    public function getPriceDontCountinFrom(): string
    {
        return $this->priceDontCountinFrom;
    }

    public function setPriceDontCountinFrom(string $priceDontCountinFrom)
    {
        $this->priceDontCountinFrom = $priceDontCountinFrom;
    }

    public function getPaymentClass(): string
    {
        return $this->paymentClass;
    }

    public function setPaymentClass(string $paymentClass)
    {
        $this->paymentClass = $paymentClass;
    }

    public function getFormat(): string
    {
        return $this->format;
    }

    public function setFormat(string $format)
    {
        $this->format = $format;
    }

    public function getFigure(): string
    {
        return $this->figure;
    }

    public function setFigure(string $figure)
    {
        $this->figure = $figure;
    }

    public function getDescription(): string
    {
        return $this->description;
    }

    public function setDescription(string $description)
    {
        $this->description = $description;
    }

    public function getIdDelivery(): DeliveryTypeDelivery
    {
        return $this->idDelivery;
    }

    public function setIdDelivery(DeliveryTypeDelivery $idDelivery)
    {
        $this->idDelivery = $idDelivery;
    }

    public function getIdPayment(): DeliveryTypePayment
    {
        return $this->idPayment;
    }

    public function setIdPayment(DeliveryTypePayment $idPayment)
    {
        $this->idPayment = $idPayment;
    }

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

    /**
     * @var bool
     *
     * @ORM\Column(name="list_order", type="boolean", nullable=false)
     */
    private $listOrder = '0';

    /**
     * @var string
     *
     * @ORM\Column(name="price", type="decimal", precision=15, scale=4, nullable=true)
     */
    private $price;

    /**
     * @var Currency
     *
     * dělá průšvih když není zapnutej i18n bundle
     * ORM\ManyToOne(targetEntity="KupShop\I18nBundle\Entity\Currency")
     * ORM\JoinColumn(name="id_currency", referencedColumnName="id", onDelete="CASCADE", nullable=false)
     */
    private $currency;

    /**
     * @var bool
     *
     * @ORM\Column(name="vat", type="boolean", nullable=false)
     */
    private $vat = '1';

    /**
     * @var string
     *
     * @ORM\Column(name="price_dont_countin_from", type="decimal", precision=15, scale=4, nullable=true)
     */
    private $priceDontCountinFrom;

    /**
     * @var string
     *
     * @ORM\Column(name="payment_class", type="string", length=20, nullable=true)
     */
    private $paymentClass;

    /**
     * @var string
     *
     * @ORM\Column(name="format", type="string", length=20, nullable=true)
     */
    private $format;

    /**
     * @var string
     *
     * @ORM\Column(name="figure", type="string", nullable=false)
     */
    private $figure = 'Y';

    /**
     * @var string
     *
     * @ORM\Column(name="description", type="text", length=16777215, nullable=true)
     */
    private $description;

    /**
     * @var \KupShop\OrderingBundle\Entity\DeliveryTypeDelivery
     *
     * @ORM\ManyToOne(targetEntity="KupShop\OrderingBundle\Entity\DeliveryTypeDelivery")
     *
     * @ORM\JoinColumns({
     *
     *   @ORM\JoinColumn(name="id_delivery", referencedColumnName="id")
     * })
     */
    private $idDelivery;

    /**
     * @var \KupShop\OrderingBundle\Entity\DeliveryTypePayment
     *
     * @ORM\ManyToOne(targetEntity="KupShop\OrderingBundle\Entity\DeliveryTypePayment")
     *
     * @ORM\JoinColumns({
     *
     *   @ORM\JoinColumn(name="id_payment", referencedColumnName="id")
     * })
     */
    private $idPayment;

    /**
     * Get listOrder.
     *
     * @return bool
     */
    public function getListOrder()
    {
        return $this->listOrder;
    }

    /**
     * Get vat.
     *
     * @return bool
     */
    public function getVat()
    {
        return $this->vat;
    }
}
