<?php

declare(strict_types=1);

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

use Seka\Portal\Modul\Terminy\Entities\Dtos\MoznostDTO;
use Seka\Portal\Modul\Terminy\Entities\Dtos\ZvoleneMoznostiDTO;
use Seka\Portal\Modul\Terminy\Entities\Registracia\ValueObjects\ZoznamZvolenychMoznostiUdalostiValueObject;
use Seka\Portal\Modul\Terminy\Entities\Udalost\ValueObjects\MoznostUdalostiValueObject;

/**
 * Class ZvoleneMoznostiDTOFactory
 *
 * @package Seka\Portal\Modul\Terminy\Entities\Dtos\Factory
 */
final class ZvoleneMoznostiDTOFactory
{
    /**
     * @param \Seka\Portal\Modul\Terminy\Entities\Registracia\ValueObjects\ZoznamZvolenychMoznostiUdalostiValueObject $obj
     *
     * @return \Seka\Portal\Modul\Terminy\Entities\Dtos\ZvoleneMoznostiDTO
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     * @throws \Spatie\LaravelData\Exceptions\CannotCreateData
     * @throws \Spatie\LaravelData\Exceptions\CannotSetComputedValue
     */
    public static function make(ZoznamZvolenychMoznostiUdalostiValueObject $obj): ZvoleneMoznostiDTO
    {
        $moznosti = $obj->toArray();
        $moznosti['moznosti'] = collect($obj->getMoznosti())->map(function (MoznostUdalostiValueObject $m) {
            return MoznostDTO::from($m->toArray());
        })->toArray();

        return ZvoleneMoznostiDTO::from($moznosti);
    }
}
