<?php


namespace App\Services;

use App\DAO\AdendoDAO;
use App\DAO\DAOResponse\DAOResponseInterface;
use App\Services\ServiceResponse\ServiceResponse;
use App\Services\ServiceResponse\ServiceResponseInterface;


class AdendoService extends Service
{
    public function getAdendoListByConsultaId(int $consulta_id) : ServiceResponse
    {
        $service_response = new ServiceResponse;
        $adendo_dao = new AdendoDAO();

        $adendo_dao_response = $adendo_dao->getAdendoListByConsultaId($consulta_id);
        switch ($adendo_dao_response->getStatus()) {
            case DAOResponseInterface::SUCESS:
                $service_response->setStatus(ServiceResponseInterface::SUCESS);
                $service_response->setData($adendo_dao_response->getData());
                break;
            case DAOResponseInterface::FOREIGN_KEY_DONT_EXISTS:
            case DAOResponseInterface::DUPLICATED_UNIQUE_KEY:
                $service_response->setStatus(ServiceResponseInterface::VALIDATION_PARAMS_ERROR);
                $service_response->setErrors($adendo_dao_response->getErrors());
                break;
            default:
                $service_response->setStatus(ServiceResponseInterface::DATABASE_CONNECTION_ERROR);
                break;
        }

        return $service_response;

    }

    public function registerAdendo (array $data_post) : ServiceResponse
    {
        $service_response = new ServiceResponse;
        $adendo_dao = new AdendoDAO();

        $adendo_dao_response = $adendo_dao->registerAdendo($data_post);
        switch ($adendo_dao_response->getStatus()) {
            case DAOResponseInterface::SUCESS:
                $service_response->setStatus(ServiceResponseInterface::SUCESS);
                break;
            case DAOResponseInterface::FOREIGN_KEY_DONT_EXISTS:
            case DAOResponseInterface::DUPLICATED_UNIQUE_KEY:
                $service_response->setStatus(ServiceResponseInterface::VALIDATION_PARAMS_ERROR);
                $service_response->setErrors($adendo_dao_response->getErrors());
                break;
            default:
                $service_response->setStatus(ServiceResponseInterface::DATABASE_CONNECTION_ERROR);
                break;
        }

        return $service_response;

    }


}