<?php

namespace DMD\LaLigaApi\Service\Common;

use DMD\LaLigaApi\Dto\TeamDto;
use DMD\LaLigaApi\Entity\Team;

class TeamFactory
{
    public static function createEntityFromDto(TeamDto $teamDto): Team
    {
        $teamEntity = new Team();
        if (!empty($teamDto->name))
        {
            $teamEntity->setName($teamDto->name);
        }
        if (!empty($teamDto->dayOfWeekForHomeGame))
        {
            $teamEntity->setDayOfTheWeekForHomeGame($teamDto->dayOfWeekForHomeGame);
        }
        if (!empty($teamDto->logo))
        {
            $teamEntity->setTeamLogo($teamDto->logo);
        }
        if (!empty($teamDto->active))
        {
            $teamEntity->setActive($teamDto->active);
        }
        if (!empty($teamDto->leagueId))
        {
            $teamEntity->setLeagueId($teamDto->leagueId);
        }
        return $teamEntity;
    }
    public static function createDtoFromEntity(Team $teamEntity): TeamDto
    {
        $teamDto = new TeamDto();
        $teamDto->fillFromEntity($teamEntity);
        return $teamDto;
    }
    public static function createDtoFromArray(array $teamArray): TeamDto
    {
        $teamDto = new TeamDto();
        $teamDto->fillFromArray($teamArray);
        $teamDto->active = true;
        return $teamDto;
    }
}