<?php

namespace App\Entity;


use App\Entity\IFace\IEntity;
use App\Utils\Utils;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="service")
 */
class EntService implements IEntity
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    protected $id;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $old_plp_id;

    /**
     * @ORM\Column(type="string",nullable=false)
     */
    protected $name;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $name_additional;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $street;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $street_no;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $zip;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $city;

    /**
     * @ORM\Column(type="integer", nullable=true, options={"unsigned" = true})
     */
    protected $country_id;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $url;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $email;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $phone_no;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $mobile_no;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $fax_no;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $comment;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $tax_no;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $invoice_mode;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $invoice_comment;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $invoice_key;

    /**
     * @ORM\Column(type="boolean", nullable=false)
     */
    protected $active;

    /**
     * @ORM\Column(type="datetime", nullable=false)
     */
    protected $creation_date;

    /**
     * EntService constructor.
     * @param ObjectManager $em
     * @param $name
     * @throws \Exception
     */
    public function __construct(ObjectManager $em, $name)
    {
        $this->name = $name;
        $this->active = true;
        $this->creation_date = new \DateTime();
    }

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

    /**
     * @return mixed
     */
    public function getOldPlpId()
    {
        return $this->old_plp_id;
    }

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

    /**
     * @return mixed
     */
    public function getNameAdditional()
    {
        return $this->name_additional;
    }

    /**
     * @return mixed
     */
    public function getStreet()
    {
        return $this->street;
    }

    /**
     * @return mixed
     */
    public function getStreetNo()
    {
        return $this->street_no;
    }

    /**
     * @return mixed
     */
    public function getZip()
    {
        return $this->zip;
    }

    /**
     * @return mixed
     */
    public function getCity()
    {
        return $this->city;
    }

    /**
     * @return mixed
     */
    public function getCountryId()
    {
        return $this->country_id;
    }

    /**
     * @return mixed
     */
    public function getUrl()
    {
        return $this->url;
    }

    /**
     * @return mixed
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * @return mixed
     */
    public function getPhoneNo()
    {
        return $this->phone_no;
    }

    /**
     * @return mixed
     */
    public function getMobileNo()
    {
        return $this->mobile_no;
    }

    /**
     * @return mixed
     */
    public function getFaxNo()
    {
        return $this->fax_no;
    }

    /**
     * @return mixed
     */
    public function getComment()
    {
        return $this->comment;
    }

    /**
     * @return mixed
     */
    public function getTaxNo()
    {
        return $this->tax_no;
    }

    /**
     * @return mixed
     */
    public function getInvoiceMode()
    {
        return $this->invoice_mode;
    }

    /**
     * @return mixed
     */
    public function getInvoiceComment()
    {
        return $this->invoice_comment;
    }

    /**
     * @return mixed
     */
    public function getInvoiceKey()
    {
        return $this->invoice_key;
    }

    /**
     * @return bool
     */
    public function isActive(): bool
    {
        return $this->active;
    }

    /**
     * @return \DateTime
     */
    public function getCreationDate(): \DateTime
    {
        return $this->creation_date;
    }

    /**
     * @param mixed $old_plp_id
     */
    public function setOldPlpId($old_plp_id): void
    {
        $this->old_plp_id = $old_plp_id;
    }

    /**
     * @param mixed $name
     */
    public function setName($name): void
    {
        $this->name = $name;
    }

    /**
     * @param mixed $name_short
     */
    public function setNameShort($name_short): void
    {
        $this->name_short = $name_short;
    }

    /**
     * @param mixed $name_addtional
     */
    public function setNameAdditional($name_addtional): void
    {
        $this->name_addtional = $name_addtional;
    }

    /**
     * @param mixed $street
     */
    public function setStreet($street): void
    {
        $this->street = $street;
    }

    /**
     * @param mixed $street_no
     */
    public function setStreetNo($street_no): void
    {
        $this->street_no = $street_no;
    }

    /**
     * @param mixed $zip
     */
    public function setZip($zip): void
    {
        $this->zip = $zip;
    }

    /**
     * @param mixed $city
     */
    public function setCity($city): void
    {
        $this->city = $city;
    }

    /**
     * @param mixed $country_id
     */
    public function setCountryId($country_id): void
    {
        $this->country_id = $country_id;
    }

    /**
     * @param mixed $url
     */
    public function setUrl($url): void
    {
        $this->url = $url;
    }

    /**
     * @param mixed $email
     */
    public function setEmail($email): void
    {
        $this->email = $email;
    }

    /**
     * @param mixed $phone_no
     */
    public function setPhoneNo($phone_no): void
    {
        $this->phone_no = $phone_no;
    }

    /**
     * @param mixed $mobile_no
     */
    public function setMobileNo($mobile_no): void
    {
        $this->mobile_no = $mobile_no;
    }

    /**
     * @param mixed $fax_no
     */
    public function setFaxNo($fax_no): void
    {
        $this->fax_no = $fax_no;
    }

    /**
     * @param mixed $comment
     */
    public function setComment($comment): void
    {
        $this->comment = $comment;
    }

    /**
     * @param mixed $tax_no
     */
    public function setTaxNo($tax_no): void
    {
        $this->tax_no = $tax_no;
    }

    /**
     * @param mixed $invoice_mode
     */
    public function setInvoiceMode($invoice_mode): void
    {
        $this->invoice_mode = $invoice_mode;
    }

    /**
     * @param mixed $invoice_comment
     */
    public function setInvoiceComment($invoice_comment): void
    {
        $this->invoice_comment = $invoice_comment;
    }

    /**
     * @param mixed $invoice_key
     */
    public function setInvoiceKey($invoice_key): void
    {
        $this->invoice_key = $invoice_key;
    }

    /**
     * @param bool $active
     */
    public function setActive(bool $active): void
    {
        $this->active = $active;
    }

    /**
     * Sets client data
     * @param ObjectManager $em
     * @param $clientData
     */
    public function setClientData(ObjectManager $em, $clientData)
    {
        $this->setName($clientData->name);
        $this->setNameAdditional($clientData->name_additional);
        $this->setStreet($clientData->street);
        $this->setStreetNo($clientData->street_no);
        $this->setZip($clientData->zip);
        $this->setCity($clientData->city);
        $this->setCountryId($clientData->country_id);
        $this->setUrl($clientData->url);
        $this->setEmail($clientData->email);
        $this->setPhoneNo($clientData->phone_no);
        $this->setMobileNo($clientData->mobile_no);
        $this->setFaxNo($clientData->fax_no);
        $this->setComment($clientData->comment);
        $this->setTaxNo($clientData->tax_no);
        $this->setInvoiceMode($clientData->invoice_mode);
        $this->setInvoiceComment($clientData->invoice_comment);
        $this->setInvoiceKey($clientData->invoice_key);
        $this->setActive($clientData->active);
    }

    /**
     * Client mapper
     * @param ObjectManager $em
     * @param bool $fullMapping
     * @return array
     */
    public function clientMapper(ObjectManager $em, $fullMapping = false)
    {
        $res = [
            'id' => $this->id,
            'old_plp_id' => $this->old_plp_id,
            'name' => $this->name,
            'name_additional' => $this->name_additional,
            'street' => $this->street,
            'street_no' => $this->street_no,
            'zip' => $this->zip,
            'city' => $this->city,
            'country_id' => $this->country_id,
            'url' => $this->url,
            'email' => $this->email,
            'phone_no' => $this->phone_no,
            'mobile_no' => $this->mobile_no,
            'fax_no' => $this->fax_no,
            'comment' => $this->comment,
            'tax_no' => $this->tax_no,
            'invoice_mode' => $this->invoice_mode,
            'invoice_comment' => $this->invoice_mode,
            'invoice_key' => $this->invoice_mode,
            'active' => $this->active,
            'v_service_contacts' => [],
            'v_service_notes' => [],
            'v_service_meetings' => [],
        ];

        if ($fullMapping) {
            $res['v_service_contacts'] = Utils::clientMap($em, $em->getRepository(EntServiceContact::class)->findBy(['service_id' => $this->getId()]));
            $res['v_service_notes'] = Utils::clientMap($em, $em->getRepository(EntServiceNote::class)->findBy(['service_id' => $this->getId()]));
            $res['v_service_meetings'] = Utils::clientMap($em, $em->getRepository(EntServiceMeeting::class)->findBy(['service_id' => $this->getId()]));
        }

        return $res;
    }

}
