<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Terminy\Entities\Dtos\Factory;

use Carbon\Carbon;
use Seka\Portal\Modul\Terminy\Entities\Dtos\UdalostDTO;
use Seka\Portal\Modul\Terminy\Entities\Dtos\MiestoKonaniaDTO;
use Seka\Portal\Modul\Terminy\Entities\Udalost\Udalost;

/**
 * Class UdalostDTOFactory
 *
 * @package Seka\Portal\Modul\Terminy\Entities\Dtos\Factory
 */
final class UdalostDTOFactory
{
    /**
     * @param \Seka\Portal\Modul\Terminy\Entities\Udalost\Udalost $udalost
     *
     * @return \Seka\Portal\Modul\Terminy\Entities\Dtos\UdalostDTO
     */
    public static function make(Udalost $udalost)
    {
        $model = $udalost->withoutRelations()->toArray();
        $model['datum_od'] = Carbon::createFromFormat('Y-m-d\TH:i', $model['datum_od']);
        $model['datum_do'] = Carbon::createFromFormat('Y-m-d\TH:i', $model['datum_do']);
        $model['miesto_konania'] = MiestoKonaniaDTO::fromModel($udalost->miestoKonania);

        $udalostDTO = new UdalostDTO($model);

        return $udalostDTO;
    }
}
