<?php

declare(strict_types=1);

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

use Carbon\Carbon;
use Seka\Portal\Modul\Terminy\Entities\Dtos\MiestoKonaniaDTO;
use Seka\Portal\Modul\Terminy\Entities\Dtos\UdalostDTO;
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
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     * @throws \Spatie\LaravelData\Exceptions\CannotCreateData
     * @throws \Spatie\LaravelData\Exceptions\CannotSetComputedValue
     */
    public static function make(Udalost $udalost): UdalostDTO
    {
        $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::from($udalost->miestoKonania);

        return UdalostDTO::from($model);
    }
}
