<?php


namespace Fifa\ConnectId\Sdk\Model\Transfer;

use DateTime;
use Fifa\ConnectId\Sdk\Model\DataStandard\PersonLocal;
use Fifa\ConnectId\Sdk\Util\ToString\Exception\ToStringException;
use Fifa\ConnectId\Sdk\Util\ToString\ToString;

class DomesticTransferDeclaration
{
    /**
     * @var string
     * @required
     */
    public $MessageId;

    /**
     * @var PersonLocal
     * @required
     */
    public $PersonLocal;

    /**
     * @var DocumentEmbedded
     */
    public $TransferCertificate;

    /**
     * @var DocumentEmbedded
     */
    public $TransferAgreement;

    /**
     * @var EmploymentContract
     */
    public $EmploymentContract;

    /**
     * @var WorkPermit
     */
    public $WorkPermit;

    /**
     * @var ResidencePermit
     */
    public $ResidencePermit;

    /**
     * @var Club
     * @required
     */
    public $EngagingClub;

    /**
     * @var Club
     * required
     */
    public $ReleasingClub;

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

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

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

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

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

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

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

    /**
     * @var int
     */
    public $EngagingTmsTransferId;

    /**
     * @var int
     */
    public $ReleasingTmsTransferId;

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

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

    /**
     * DomesticTransferDeclaration constructor.
     * @param string $messageId
     * @param PersonLocal $personLocal
     * @param Club $engagingClub
     * @param Club $releasingClub
     * @param string $playerLevelInReleasingClub
     * @param string $playerLevelInEngagingClub
     * @param string $transferNature
     * @param DateTime $contractEndDate
     * @param string $sellOnFee
     * @throws ToStringException
     */
    public function __construct(string $messageId, PersonLocal $personLocal, Club $engagingClub, Club $releasingClub,
                                string $playerLevelInEngagingClub, string $playerLevelInReleasingClub, string $transferNature, DateTime $contractEndDate, string $sellOnFee)
    {
        $this->MessageId = $messageId;
        $this->PersonLocal = $personLocal;
        $this->EngagingClub = $engagingClub;
        $this->ReleasingClub = $releasingClub;
        $this->PlayerLevelInEngagingClub = $playerLevelInEngagingClub;
        $this->PlayerLevelInReleasingClub = $playerLevelInReleasingClub;
        $this->TransferNature = $transferNature;
        $this->setContractEndDate($contractEndDate);
        $this->SellOnFee = $sellOnFee;
    }

    /**
     * Gets DateTime object and sets its string representation to ContractEndDate property
     *
     * @param DateTime $contractEndDate
     * @throws ToStringException
     */
    public function setContractEndDate(DateTime $contractEndDate)
    {
        $this->ContractEndDate = ToString::getValue($contractEndDate);
    }

    /**
     * Gets DateTime object and sets its string representation to TransferAgreementDate property
     *
     * @param DateTime $transferAgreementDate
     * @throws ToStringException
     */
    public function setTransferAgreementDate(DateTime $transferAgreementDate)
    {
        $this->TransferAgreementDate = ToString::getValue($transferAgreementDate);
    }

    /**
     * @return string
     */
    public function __toString()
    {
        $dataToSerialize = [];
        $dataToSerialize[] = sprintf('MessageId: %s', $this->MessageId);

        $dataToSerialize[] = sprintf(
            'PlayerLevelInReleasingClub: %s, PlayerLevelInEngagingClub: %s, TransferNature: %s, ContractEndDate: %s, SellOnFee: %s',
            $this->PlayerLevelInReleasingClub, $this->PlayerLevelInEngagingClub, $this->TransferNature, $this->ContractEndDate, $this->SellOnFee
        );

        $dataToSerialize[] = sprintf(
            'TransferAgreementDate: %s, EngagingTmsTransferId: %s, ReleasingTmsTransferId: %s',
            $this->TransferAgreementDate, $this->EngagingTmsTransferId, $this->ReleasingTmsTransferId
        );

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

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

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

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

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

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

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

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

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

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

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

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