<?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 \ReflectionException
     */
    public static function make(ZoznamZvolenychMoznostiUdalostiValueObject $obj): ZvoleneMoznostiDTO
    {
        $moznosti = $obj->toArray();
        $moznosti['moznosti'] = collect($obj->getMoznosti())->map(function (MoznostUdalostiValueObject $m) {
            return new MoznostDTO($m->toArray());
        })->toArray();

        return new ZvoleneMoznostiDTO($moznosti);
    }
}
