<?php

namespace Fifa\ConnectId\Sdk\Model\Transfer;

use Fifa\ConnectId\Sdk\Model\DataStandard\PersonLocal;
use InvalidArgumentException;

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

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

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

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

    /**
     * @internal Use corresponding setter and getter methods
     *
     * @var string
     * @required
     */
    public $PlayerTrainedInOtherMemberAssociation;

    /**
     * FirstProRegistration constructor.
     * @param string $messageId
     * @param PersonLocal $player
     * @param Club $club
     * @param string $clubStatus
     * @param bool $playerTrainedInOtherMemberAssociation
     */
    public function __construct(string $messageId, PersonLocal $player, Club $club, string $clubStatus, bool $playerTrainedInOtherMemberAssociation)
    {
        $this->MessageId = $messageId;
        $this->Player = $player;
        $this->Club = $club;
        $this->ClubStatus = $clubStatus;
        $this->setPlayerTrainedInOtherMemberAssociation($playerTrainedInOtherMemberAssociation);
    }

    /**
     * @param bool $playerTrainedInOtherMemberAssociation
     */
    public function setPlayerTrainedInOtherMemberAssociation(bool $playerTrainedInOtherMemberAssociation)
    {
        $this->PlayerTrainedInOtherMemberAssociation = $playerTrainedInOtherMemberAssociation ? '1' : '0';
    }

    /**
     * @return bool
     * @throws InvalidArgumentException
     */
    public function getPlayerTrainedInOtherMemberAssociation(): bool
    {
        $val = $this->PlayerTrainedInOtherMemberAssociation;
        switch ($val) {
            case '0':
            case 'false':
                return false;
            case '1':
            case 'true':
                return true;
            default:
                throw new InvalidArgumentException(sprintf('Incorrect boolean value: %s', $val));
        }
    }

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

        $dataToSerialize[] = sprintf(
            'ClubStatus: %s, PlayerTrainedInOtherMemberAssociation: %s',
            $this->ClubStatus, $this->PlayerTrainedInOtherMemberAssociation
        );

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

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

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