<?php
namespace Fifa\ConnectId\Sdk\Model\DataStandard;

use DateTime;
use Fifa\ConnectId\Sdk\Util\ToString\Exception\ToStringException;
use Fifa\ConnectId\Sdk\Util\ToString\ToString;

/**
 * Class PersonLocal
 * @package Fifa\ConnectId\Sdk\Model\DataStandard
 */
class PersonLocal
{
    /**
     * @var string
     * @required
     */
    public $LocalLastName;

    /**
     * @var string
     * @required
     */
    public $Gender;

    /**
     * @var string
     * @required
     */
    public $Nationality;

    /**
     * Date in format "Y-m-d" (ref. http://php.net/manual/en/function.date.php)
     *
     * @var string
     * @required
     */
    public $DateOfBirth;

    /**
     * @var string
     * @required
     */
    public $CountryOfBirth;

    /**
     * @var string
     * @required
     */
    public $PlaceOfBirth;

    /**
     * @var string
     * @required
     */
    public $LocalLanguage;

    /**
     * @var string
     * @required
     */
    public $LocalCountry;

    /**
     * @var string
     */
    public $LocalFirstName;

    /**
     * @var string
     */
    public $LocalBirthName;

    /**
     * @var Photo
     */
    public $Photo;

    /**
     * @var LocalPersonName
     */
    public $LocalPersonName;

    /**
     * @var NationalIdentifier
     */
    public $NationalIdentifier;

    /**
     * @var PlayerRegistration[]
     */
    public $PlayerRegistration = [];

    /**
     * @var TeamOfficialRegistration[]
     */
    public $TeamOfficialRegistration = [];

    /**
     * @var MatchOfficialRegistration[]
     */
    public $MatchOfficialRegistration = [];

    /**
     * @var OrganisationOfficialRegistration[]
     */
    public $OrganisationOfficialRegistration =[];

    /**
     * @var string
     * @required
     */
    public $PersonFIFAId;

    /**
     * @var string
     */
    public $InternationalFirstName;

    /**
     * @var string
     */
    public $InternationalLastName;

    /**
     * @var string
     */
    public $RegionOfBirth;

    /**
     * @var string
     */
    public $LocalSystemMAId;

    /**
     * @var string
     */
    public $SecondNationality;

    /**
     * @var string
     */
    public $PopularName;

    /**
     * PersonLocal constructor.
     *
     * @param string $LocalLastName
     * @param string $Gender
     * @param string $Nationality
     * @param DateTime $DateOfBirth
     * @param string $CountryOfBirth
     * @param string $PlaceOfBirth
     * @param string $LocalLanguage
     * @param string $LocalCountry
     * @param string $PersonFIFAId
     *
     * @throws ToStringException
     */
    public function __construct(string $LocalLastName, string $Gender, string $Nationality, DateTime $DateOfBirth, string $CountryOfBirth, string $PlaceOfBirth, string $LocalLanguage, string $LocalCountry, string $PersonFIFAId)
    {
        $this->setDateOfBirth($DateOfBirth);
        $this->Gender = $Gender;
        $this->Nationality = $Nationality;
        $this->CountryOfBirth = $CountryOfBirth;
        $this->PlaceOfBirth = $PlaceOfBirth;
        $this->LocalLastName = $LocalLastName;
        $this->LocalLanguage = $LocalLanguage;
        $this->LocalCountry = $LocalCountry;
        $this->PersonFIFAId = $PersonFIFAId;
    }

    /**
     * @return string
     */
    public function __toString()
    {
        $dataToSerialize = [];
        $dataToSerialize[] = sprintf(
            'LocalLastName: %s, Gender: %s, Nationality: %s, CountryOfBirth: %s, DateOfBirth: %s, PlaceOfBirth: %s, LocalLanguage: %s, LocalCountry: %s',
            $this->LocalLastName, $this->Gender, $this->Nationality, $this->CountryOfBirth, $this->DateOfBirth, $this->PlaceOfBirth, $this->LocalLanguage, $this->LocalCountry
        );

        $dataToSerialize[] = sprintf(
            'LocalFirstName: %s, LocalBirthName: %s, PersonFIFAId: %s, InternationalFirstName: %s, InternationalLastName: %s, RegionOfBirth: %s, LocalSystemMAId: %s',
            $this->LocalFirstName, $this->LocalBirthName, $this->PersonFIFAId, $this->InternationalFirstName, $this->InternationalLastName, $this->RegionOfBirth, $this->LocalSystemMAId
        );

        if (!is_null($this->LocalPersonName)) {
            $dataToSerialize[] = sprintf('LocalPersonName: [%s]', $this->LocalPersonName);
        }

        if (!is_null($this->NationalIdentifier)) {
            $dataToSerialize[] = sprintf('NationalIdentifier: [%s]', $this->NationalIdentifier);
        }

        if (!empty($this->PlayerRegistration)) {
            $dataToSerialize[] = sprintf('PlayerRegistration: [%s]', join('; ', $this->PlayerRegistration));
        }

        if (!empty($this->TeamOfficialRegistration)) {
            $dataToSerialize[] = sprintf('TeamOfficialRegistration: [%s]', join('; ', $this->TeamOfficialRegistration));
        }

        if (!empty($this->MatchOfficialRegistration)) {
            $dataToSerialize[] = sprintf('MatchOfficialRegistration: [%s]', join('; ', $this->MatchOfficialRegistration));
        }

        if (!empty($this->OrganisationOfficialRegistration)) {
            $dataToSerialize[] = sprintf('OrganisationOfficialRegistration: [%s]', join('; ', $this->OrganisationOfficialRegistration));
        }

        if (!is_null($this->Photo)) {
            $dataToSerialize[] = sprintf('Photo: [%s]', $this->Photo);
        }

        if (!is_null($this->SecondNationality)){
            $dataToSerialize[] = sprintf('SecondNationality: [%s]', $this->SecondNationality);
        }

        if (!is_null($this->PopularName)){
            $dataToSerialize[] = sprintf('SecondNationality: [%s]', $this->PopularName);
        }

        return join(', ', $dataToSerialize);
    }

    /**
     * Gets DateTime object and sets its string representation to DateOfBirth property
     *
     * @param DateTime $dateOfBirth
     * @return PersonLocal
     * @throws ToStringException
     */
    public function setDateOfBirth(DateTime $dateOfBirth): PersonLocal
    {
        $this->DateOfBirth = ToString::getValue($dateOfBirth);
        return $this;
    }

    /**
     * @param PlayerRegistration $playerRegistration
     * @return PersonLocal
     */
    public function addPlayerRegistration(PlayerRegistration $playerRegistration): PersonLocal
    {
        $this->PlayerRegistration[] = $playerRegistration;
        return $this;
    }

    /**
     * @param TeamOfficialRegistration $teamOfficialRegistration
     * @return PersonLocal
     */
    public function addTeamOfficialRegistration(TeamOfficialRegistration $teamOfficialRegistration): PersonLocal
    {
        $this->TeamOfficialRegistration[] = $teamOfficialRegistration;
        return $this;
    }

    /**
     * @param MatchOfficialRegistration $matchOfficialRegistration
     * @return PersonLocal
     */
    public function addMatchOfficialRegistration(MatchOfficialRegistration $matchOfficialRegistration): PersonLocal
    {
        $this->MatchOfficialRegistration[] = $matchOfficialRegistration;
        return $this;
    }

    /**
     * @param OrganisationOfficialRegistration $organisationOfficialRegistration
     * @return PersonLocal
     */
    public function addOrganisationOfficialRegistration(OrganisationOfficialRegistration $organisationOfficialRegistration): PersonLocal
    {
        $this->OrganisationOfficialRegistration[] = $organisationOfficialRegistration;
        return $this;
    }
}