<?php namespace App\Mappers;

use App\Entities\DocumentoGerado\DocumentoGerado;
use App\Services\EncryptService;
use App\Services\JWTService;
use App\Utils\Collections\GeneralCollection;
use App\ViewModels\DocumentoGerado\DocumentoGeradoListViewModel\DocumentoGeradoListViewModel;

class DocumentoGeradoMapper
{

# ----------------------------------------------------------------------------------------------------------------#

    public static function getDocumentoGeradoListVMCollectionFromArray (array $response_array) : GeneralCollection {
        $arquivo_details_vm_collection = new GeneralCollection();
        foreach ($response_array as $row) {
            $key = "HLuM5EYw5cd0vdJR9yLlM6wt2vte5iniQBqE70nZuhK=";
            if(file_exists($row['arquivo']) === true){
                $get_file = file_get_contents($row['arquivo']);
            }else{
                $get_file = '';
            }
            $encrypt = new EncryptService();

            $msg_decrypted = $encrypt->my_decrypt($get_file, $key);
            $base64 = base64_encode($msg_decrypted);

            $procedimento_details_vm = DocumentoGeradoMapper::getDocumentoGeradoListVMFromArray($row);
            $arquivo_details_vm_collection->push($procedimento_details_vm);
        }
        return $arquivo_details_vm_collection;
    }

    public static function getDocumentoGeradoDetailsVMFromArray (array $arquivo, $file) : DocumentoGeradoListViewModel {
        return DocumentoGeradoListViewModel::builder()
            ->setId($arquivo['id'])
            ->setIdCliente($arquivo['id_cliente'])
            ->setIdPet($arquivo['id_pet'])
            ->setCriadoEm($arquivo['criado_em'])
            ->setDescricao($arquivo['descricao'])
            ->setUrl($file)
            ->build();
    }

    public static function getDocumentoGeradoListVMFromArray (array $arquivo) : DocumentoGeradoListViewModel {
        return DocumentoGeradoListViewModel::builder()
            ->setId($arquivo['id'])
            ->setIdCliente($arquivo['id_cliente'])
            ->setIdPet($arquivo['id_pet'])
            ->setDescricao($arquivo['descricao'])
            ->setCriadoEm($arquivo['criado_em'])
            ->setUrl([])
            ->build();
    }

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

# ----------------------------------------------------------------------------------------------------------------#


}