<?php

declare(strict_types=1);

namespace Seka\Terminy\Dtos\Factory;

use Carbon\Carbon;
use Seka\Terminy\Dtos\UdalostDTO;
use Seka\Terminy\Dtos\MiestoKonaniaDTO;
use Seka\Terminy\Models\Udalost\Udalost;

/**
 * Class UdalostDTOFactory
 *
 * @package Seka\Terminy\Dtos\Factory
 */
final class UdalostDTOFactory
{
    /**
     * @param \Seka\Terminy\Models\Udalost\Udalost $udalost
     *
     * @return \Seka\Terminy\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;
    }
}
