<?php

namespace App\Services;

use App\DAO\LogsysDAO;
use App\DAO\DAOResponse\DAOResponseInterface;
use App\Services\ServiceResponse\ServiceResponse;
use App\Services\ServiceResponse\ServiceResponseInterface;
use App\Mappers\LogsysMapper;

class LogsysService extends Service {
	
	public function register($path_info,$requets_method,$params) : ServiceResponse {
		$service_response = new ServiceResponse;
		$logsys_dao = new LogsysDAO();
		$objlogysys = LogsysMapper::getLogsysRegistrationVMFromArray($path_info,$requets_method,$params);
		$logsys_dao_response = $logsys_dao->registerLog($objlogysys);
		switch ($logsys_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($logsys_dao_response->getErrors());
				break;
			default:
				$service_response->setStatus(ServiceResponseInterface::DATABASE_CONNECTION_ERROR);
				break;
		}
		
		return $service_response;
		
	}
}