<?php namespace App\Mappers;



use App\Entities\Especie\Especie;
use App\Services\JWTService;
use App\Utils\Collections\GeneralCollection;
use App\ViewModels\Especie\EspecieDetailsViewModel\EspecieDetailsViewModel;
use App\ViewModels\Especie\EspecieRegistrationViewModel\EspecieRegistrationViewModel;
use App\ViewModels\Especie\EspecieUpdateViewModel\EspecieUpdateViewModel;

class EspecieMapper
{
    public static function getEspecieRegistrationVMFromArray (array $data) : EspecieRegistrationViewModel {
        return EspecieRegistrationViewModel::builder()
            ->setNome($data['nome'])
            ->build();
    }
    public static function getEspecieFromEspecieRegistrationVM (EspecieRegistrationViewModel $exame_registration_vm) : Especie {
        return Especie::builder()
            ->setNome($exame_registration_vm->getNome())
            ->build();
    }

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

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

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

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

    public static function getEspecieFromEspecieUpdateVM (EspecieUpdateViewModel $exame_update_vm) : Especie {
        $exame = new Especie();
        if ($exame_update_vm->getNome()) {
            $exame->setNome($exame_update_vm->getNome());
        }
        return $exame;

    }
}