<?php

namespace App\Entity;


use App\Entity\IFace\IEntity;
use App\Utils\Utils;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Config\Definition\Exception\Exception;

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

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

    /**
     * @ORM\Column(name="gender", type="string", columnDefinition="enum('male', 'female', 'diverse')")
     */
    protected $gender;

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

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

    /**
     * @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 $department;

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

    /**
     * @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 $comment;

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

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


    /**
     * EntServiceContact constructor.
     * @param ObjectManager $em
     * @param EntService $entService
     * @param $lastName
     * @throws \Exception
     */
    public function __construct(ObjectManager $em, EntService $entService, $lastName)
    {
        if (is_null($entService->getId())) {
            throw new Exception('no id found');
        }

        $this->service_id = $entService->getId();
        $this->lastname = $lastName;
        $this->creation_date = new \DateTime();
    }

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

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

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

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

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

    /**
     * @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 getDepartment()
    {
        return $this->department;
    }

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

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

    /**
     * @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 getComment()
    {
        return $this->comment;
    }

    /**
     * @param mixed $gender
     */
    public function setGender($gender): void
    {
        if (!is_null($gender) && !Utils::isValidGender($gender)) {
            throw new Exception('invalid gender');
        }
        $this->gender = $gender;
    }

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

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

    /**
     * @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 $department
     */
    public function setDepartment($department): void
    {
        $this->department = $department;
    }

    /**
     * @param mixed $date_of_birth
     */
    public function setDateOfBirth($date_of_birth): void
    {
        $this->date_of_birth = !is_null($date_of_birth) ? \DateTime::createFromFormat('Y-m-d', $date_of_birth) : $date_of_birth;
    }

    /**
     * @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 $comment
     */
    public function setComment($comment): void
    {
        $this->comment = $comment;
    }

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

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

    /**
     * Sets client data
     * @param ObjectManager $em
     * @param $clientData
     */
    public function setClientData(ObjectManager $em, $clientData)
    {
        $this->setGender($clientData->gender);
        $this->setFirstname($clientData->firstname);
        $this->setLastname($clientData->lastname);
        $this->setEmail($clientData->email);
        $this->setPhoneNo($clientData->phone_no);
        $this->setMobileNo($clientData->mobile_no);
        $this->setFaxNo($clientData->fax_no);
        $this->setDepartment($clientData->department);
        $this->setDateOfBirth($clientData->date_of_birth);
        $this->setStreet($clientData->street);
        $this->setStreetNo($clientData->street_no);
        $this->setZip($clientData->zip);
        $this->setCity($clientData->city);
        $this->setCountryId($clientData->country_id);
        $this->setComment($clientData->comment);
        $this->setIsxmasMailRecipient($clientData->is_xmas_mail_recipient);
    }

    /**
     * Client mapper
     * @param ObjectManager $em
     * @param bool $fullMapping
     * @return array
     */
    public function clientMapper(ObjectManager $em, $fullMapping = false)
    {
        return [
            'id' => $this->id,
            'service_id' => $this->service_id,
            'gender' => $this->gender,
            'firstname' => $this->firstname,
            'lastname' => $this->lastname,
            'email' => $this->email,
            'phone_no' => $this->phone_no,
            'mobile_no' => $this->mobile_no,
            'fax_no' => $this->fax_no,
            'department' => $this->department,
            'date_of_birth' => $this->date_of_birth,
            'street' => $this->street,
            'street_no' => $this->street_no,
            'zip' => $this->zip,
            'city' => $this->city,
            'country_id' => $this->country_id,
            'comment' => $this->comment,
            'is_xmas_mail_recipient' => $this->is_xmas_mail_recipient,
        ];
    }

}
