<?php namespace App\Mappers;



use App\Entities\Exame\Exame;
use App\Services\JWTService;
use App\Utils\Collections\GeneralCollection;
use App\ViewModels\Exame\ExameDetailsViewModel\ExameDetailsViewModel;
use App\ViewModels\Exame\ExameRegistrationViewModel\ExameRegistrationViewModel;
use App\ViewModels\Exame\ExameUpdateViewModel\ExameUpdateViewModel;

class ExameMapper
{
    public static function getExameRegistrationVMFromArray (array $data) : ExameRegistrationViewModel {
        return ExameRegistrationViewModel::builder()
            ->setNome($data['nome'])
            ->build();
    }
    public static function getExameFromExameRegistrationVM (ExameRegistrationViewModel $exame_registration_vm) : Exame {
        return Exame::builder()
            ->setNome($exame_registration_vm->getNome())
            ->build();
    }

    public static function getExameDetailsVMFromArray (array $exame) : ExameDetailsViewModel {
        return ExameDetailsViewModel::builder()
            ->setId($exame['id'])
            ->setNome($exame['nome'])
            ->build();
    }

    public static function getExameDetailsVMCollectionFromArray (array $response_array) : GeneralCollection {
        $exame_details_vm_collection = new GeneralCollection();
        foreach ($response_array as $row) {
            $exame_details_vm = ExameMapper::getExameDetailsVMFromArray($row);
            $exame_details_vm_collection->push($exame_details_vm);
        }
        return $exame_details_vm_collection;
    }

    public static function getExamesDetailsArrayFromExameDetailsVMCollection (GeneralCollection $paciente_details_vm_collection) : array {
        return $paciente_details_vm_collection->toArray();
    }

    public static function getExameUpdateVMFromArray(array $data) : ExameUpdateViewModel {
        $exame_update_vm = new ExameUpdateViewModel ();
        if (isset($data['nome'])) {
            $exame_update_vm->setNome($data['nome']);
        }
        return $exame_update_vm;
    }

    public static function getExameFromExameUpdateVM (ExameUpdateViewModel $exame_update_vm) : Exame {
        $exame = new Exame();
        if ($exame_update_vm->getNome()) {
            $exame->setNome($exame_update_vm->getNome());
        }
        return $exame;

    }
}