<?php namespace App\Mappers;



use App\Entities\Raca\Raca;
use App\Services\JWTService;
use App\Utils\Collections\GeneralCollection;
use App\ViewModels\Raca\RacaDetailsViewModel\RacaDetailsViewModel;
use App\ViewModels\Raca\RacaRegistrationViewModel\RacaRegistrationViewModel;
use App\ViewModels\Raca\RacaUpdateViewModel\RacaUpdateViewModel;

class RacaMapper
{
    public static function getRacaRegistrationVMFromArray (array $data) : RacaRegistrationViewModel {
        return RacaRegistrationViewModel::builder()
            ->setNome($data['nome'])
            ->setIdEspecie($data['id_especie'])
            ->build();
    }
    public static function getRacaFromRacaRegistrationVM (RacaRegistrationViewModel $raca_registration_vm) : Raca {
        return Raca::builder()
            ->setNome($raca_registration_vm->getNome())
            ->setIdEspecie($raca_registration_vm->getIdEspecie())
            ->build();
    }

    public static function getRacaDetailsVMFromArray (array $raca) : RacaDetailsViewModel {
        return RacaDetailsViewModel::builder()
            ->setId((int)$raca['id'])
            ->setNome($raca['nome'])
            ->setIdEspecie((int)$raca['id_especie'])
            ->setEspecie($raca['especie'])
            ->build();
    }

    public static function getRacaDetailsVMCollectionFromArray (array $response_array) : GeneralCollection {
        $raca_details_vm_collection = new GeneralCollection();
        foreach ($response_array as $row) {
            $raca_details_vm = RacaMapper::getRacaDetailsVMFromArray($row);
            $raca_details_vm_collection->push($raca_details_vm);
        }
        return $raca_details_vm_collection;
    }

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

    public static function getRacaUpdateVMFromArray(array $data) : RacaUpdateViewModel {
        $raca_update_vm = new RacaUpdateViewModel ();
        if (isset($data['nome'])) {
            $raca_update_vm->setNome($data['nome']);
            $raca_update_vm->setIdEspecie($data['id_especie']);
        }
        return $raca_update_vm;
    }

    public static function getRacaFromRacaUpdateVM (RacaUpdateViewModel $raca_update_vm) : Raca {
        $raca = new Raca();
        if ($raca_update_vm->getNome()) {
            $raca->setNome($raca_update_vm->getNome());
        }
        if ($raca_update_vm->getIdEspecie()) {
            $raca->setIdEspecie($raca_update_vm->getIdEspecie());
        }
        return $raca;

    }
}
