<?php

namespace DMD\LaLigaApi\Service\League;

use DMD\LaLigaApi\Dto\LeagueDto;
use DMD\LaLigaApi\Entity\League;

class LeagueFactory
{
    public static function create(LeagueDto $leagueDto): League
    {
        $leagueEntity = new League();
        if (!empty($leagueDto->name))
        {
            $leagueEntity->setName($leagueDto->name);
        }
        if (!empty($leagueDto->logo))
        {
            $leagueEntity->setLogo($leagueDto->logo);
        }
        if (!empty($leagueDto->description))
        {
            $leagueEntity->setDescription($leagueDto->description);
        }
        if (isset($leagueDto->pointsPerWin))
        {
            $leagueEntity->setPointsPerWin($leagueDto->pointsPerWin);
        }
        if (!empty($leagueDto->pointsPerDraw))
        {
            $leagueEntity->setPointsPerDraw($leagueDto->pointsPerDraw);
        }
        if (!empty($leagueDto->pointsPerLoss))
        {
            $leagueEntity->setPointsPerLoss($leagueDto->pointsPerLoss);
        }
        if (!empty($leagueDto->matchesBetweenTeams))
        {
            $leagueEntity->setMatchesBetweenTeams($leagueDto->matchesBetweenTeams);
        }
        if (!empty($leagueDto->blockedMatchDates))
        {
            $leagueEntity->setBlockedMatchDates($leagueDto->blockedMatchDates);
        }
        if (!empty($leagueDto->city))
        {
            $leagueEntity->setCity($leagueDto->city);
        }
        if (isset($leagueDto->isPublic))
        {
            $leagueEntity->setIsPublic($leagueDto->isPublic);
        }
        else
        {
            $leagueEntity->setIsPublic(true);
        }
        $leagueEntity->setActive(true);
        return $leagueEntity;
    }
}