<?php

namespace App\Mappers;

use App\Entities\Galeria\Galeria;
use App\Services\JWTService;
use App\Utils\Collections\GeneralCollection;
use App\ViewModels\Galeria\GaleriaListViewModel\GaleriaListViewModel;
use App\ViewModels\Galeria\GaleriaRegistrationViewModel\GaleriaRegistrationViewModel;
use PHPUnit\Framework\MockObject\Exception;

class GaleriaMapper {

	public static function getGaleriaRegistrationVMFromArray(array $data, string $url): GaleriaRegistrationViewModel {

		return GaleriaRegistrationViewModel::builder()->setDescricao( $data ['descricao'] )
			->setIdClinica( $data ['id_clinica'] )
			->setIdMedico( $data ['id_medico'] )
			->setIdPaciente( $data ['id_paciente'] )
			->setImagem( $url )
			->build();

	}

	public static function getGaleriaFromGaleriaRegistrationVM(GaleriaRegistrationViewModel $procedimento_registration_vm): Galeria {

		return Galeria::builder()->setIdClinica( $procedimento_registration_vm->getIdClinica() )
			->setIdMedico( $procedimento_registration_vm->getIdMedico() )
			->setIdPaciente( $procedimento_registration_vm->getIdPaciente() )
			->setImagem( $procedimento_registration_vm->getImagem() )
			->setDescricao( $procedimento_registration_vm->getDescricao() )
			->build();

	}

	# ----------------------------------------------------------------------------------------------------------------#
	public static function getGaleriaListVMCollectionFromArray(array $response_array): GeneralCollection {

		$procedimento_details_vm_collection = new GeneralCollection();
		foreach ( $response_array as $row ) {
			$get_file = "";

			$procedimento_details_vm = GaleriaMapper::getGaleriaDetailsVMFromArray( $row, $get_file );
			$procedimento_details_vm_collection->push( $procedimento_details_vm );
		}
		return $procedimento_details_vm_collection;

	}

	public static function getGaleriaDetailsVMCollectionFromArray(array $response_array): GeneralCollection {

		$procedimento_details_vm_collection = new GeneralCollection();
		foreach ( $response_array as $row ) {
			try {
				$get_file = file_get_contents( $row ['imagem'] );

				$procedimento_details_vm = GaleriaMapper::getGaleriaDetailsVMFromArray( $row, $get_file );
				$procedimento_details_vm_collection->push( $procedimento_details_vm );
			} catch ( Exception $ecp ) {
				$exception = $ecp;
			}
		}
		return $procedimento_details_vm_collection;

	}

	public static function getGaleriaDetailsVMFromArray(array $procedimento, string $filebase64): GaleriaListViewModel {

		return GaleriaListViewModel::builder()->setId( $procedimento ['id'] )
			->setIdClinica( $procedimento ['id_clinica'] )
			->setIdMedico( $procedimento ['id_medico'] )
			->setIdPaciente( $procedimento ['id_paciente'] )
			->setDescricao( $procedimento ['descricao'] )
			->setImagem( $filebase64 )
			->build();

	}

	public static function getGaleriaDetailsArrayFromProcedimentoDetailsVMCollection(GeneralCollection $paciente_details_vm_collection): array {

		return $paciente_details_vm_collection->toArray();

	}

}