<?php

namespace App\Mappers;

use App\Services\LogService;
use App\Utils\Collections\GeneralCollection;
use App\Utils\ResponseException;
use App\ViewModels\Dashboard\DashboardMedicoViewModel\DashboardMedicoViewModel;
use App\ViewModels\Dashboard\DashboardPacienteViewModel\DashboardPacienteViewModel;

class DashboardMapper {

	public static function getDashboardMedicoVMFromArray(array $response_array): DashboardMedicoViewModel {

		try {
			return DashboardMedicoViewModel::builder()->setData( $response_array ['data'] )
				->setHoraInicio( $response_array ['hora_inicio'] )
				->setHoraFinal( $response_array ['hora_final'] )
				->setProcedimento( $response_array ['procedimento'] )
				->setPacienteId( $response_array ['paciente_id'] )
				->setIdProcedimento( $response_array ['id_procedimento'] )
				->setTipoProcedimento( $response_array ['tipo_procedimento'] )
				->setIdAgendamento( $response_array ['id_agendamento'] )
				->setIdRequisicao( $response_array ['id_requisicao'] ?? 0)
				->setNome( $response_array ['nome'] )
				->setTelefone1( $response_array ['telefone_1'] )
				->setAtrasado( $response_array ['atrasado'] )
				->setIdConsulta( $response_array ['id_consulta'] )
				->setIdTipoProcedimento( $response_array ['id_tipo_procedimento'] )
				->setIdPet( $response_array ['id_pet'] )
				->setNomePet( $response_array ['nome_pet'] )
				->setIdCliente( $response_array ['id_cliente'] )
				->setStatusSala( $response_array ['status_sala'] ?? 0 )
				->build();
		} catch ( ResponseException $exception ) {
			(new LogService())->log_response_exception( $exception );
		}

	}

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

		$collection = new GeneralCollection();
		foreach ( $response_array as $row ) {
			$collection->push( self::getDashboardMedicoVMFromArray( $row ) );
		}
		return $collection;

	}

	public static function getDashboardPacienteVMFromArray(array $response_array): DashboardPacienteViewModel {

		try {
			return DashboardPacienteViewModel::builder()->setdata( $response_array ['data'] )
				->setdescricao_procedimento( $response_array ['descricao_procedimento'] )
				->setdescricao_tipo_procedimento( $response_array ['descricao_tipo_procedimento'] )
				->sethora_final( $response_array ['hora_final'] )
				->sethora_inicio( $response_array ['hora_inicio'] )
				->setid_agendamento( $response_array ['id_agendamento'] )
				->setid_requisicao( $response_array ['id_requisicao'] ?? 0)
				->build();
		} catch ( ResponseException $exception ) {
			(new LogService())->log_response_exception( $exception );
		}

	}

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

		$collection = new GeneralCollection();
		foreach ( $response_array as $row ) {
			$collection->push( self::getDashboardPacienteVMFromArray( $row ) );
		}
		return $collection;

	}





    public static function getDashboardMedicoTelevetVMFromArray(array $response_array): DashboardMedicoViewModel {

        try {
            return DashboardMedicoViewModel::builder()
                ->setHoraInicio( $response_array ['hora_inicio'] )
                ->setHoraFinal( $response_array ['hora_final'] )
                ->setData( $response_array ['data_agenda'] )
                ->setProcedimento( $response_array ['id_procedimento'] )
                ->setPacienteId( $response_array ['id_paciente'] ?? 0 )
                ->setIdProcedimento( $response_array ['id_procedimento'] ?? 0)
                ->setTipoProcedimento( $response_array ['tipo_procedimento'] ?? 0)
                ->setIdAgendamento( $response_array ['id_agendamento'] ?? 0)
                ->setIdRequisicao( $response_array ['id_requisicao'] ?? 0)
                ->setNome( $response_array ['nome_pessoa'] ?? 0)
                ->setTelefone1( $response_array ['telefone_1'] ?? 0)
                ->setAtrasado( $response_array ['atrasado'] ?? 0)
                ->setIdConsulta( $response_array ['id_consulta'] ?? 0)
                ->setIdTipoProcedimento( $response_array ['id_tipo_procedimento'] ?? 0)
                ->setIdPet( $response_array ['id_pet'] ?? 0)
                ->setNomePet( $response_array ['nome_pet'] ?? 0)
                ->setIdCliente( $response_array ['id_cliente'] ?? 0)
                ->build();
        } catch ( ResponseException $exception ) {
            (new LogService())->log_response_exception( $exception );
        }

    }

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

        $collection = new GeneralCollection();
        foreach ( $response_array as $row ) {
            $collection->push( self::getDashboardMedicoTelevetVMFromArray( $row ) );
        }
        return $collection;

    }






}