<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Respuestas
 *
 * @author root
 */
class RespuestasSistema {

    //put your code here
    const EXITO = 'EXITO';
    const INFO = 'INFO';
    const FALLO = 'FALLO';
    const ALERTA = 'ALERTA';
    const ERROR = 'ERROR';

    public static function responseJson($respuesta, $mensaje, $datos = null) {
        echo self::respuesta($respuesta, $mensaje, $datos);
    }
    
    public static function respuesta($respuesta, $mensaje, $datos = null, $error = null) {
        if(!empty(SesionCliente::valor("IDLOG"))):
            Log::respuestaOperacion(SesionCliente::valor("IDLOG"), $respuesta, $mensaje);
        endif;
        SesionCliente::eliminar("IDLOG");
        return json_encode(
            array(
                'RESPUESTA' => $respuesta, 
                'MENSAJE' => $mensaje,
                'DATOS' => $datos, 
                'CODIGO' => $error, 'ERROR' => $error
            )
        );
    }

    static public function exito($mensaje = null, $datos = null) {
        if( is_array($mensaje)  ){
            $tmp = $datos;
            $datos = $mensaje;
            $mensaje = $tmp;
        }
        return self::respuesta(self::EXITO, $mensaje, $datos );
    }

    static public function alerta($mensaje, $datos = null) {
        return self::respuesta(self::ALERTA, $mensaje, $datos );
    }

    static public function fallo($mensaje, $datos = null) {
        return self::respuesta(self::FALLO, $mensaje, $datos );
    }

    static public function error($mensaje, $codigo = null) {
        return self::respuesta(self::ERROR, $mensaje, null, $codigo );
    }

    public static function getRespuesta() {
        return self::$respuesta;
    }

    public static function getMensajeRespuesta() {
        return self::$mensaje;
    }
    
}

