<?php

defined('BASEPATH') OR exit('No direct script access allowed');

// This can be removed if you use __autoload() in config.php OR use Modular Extensions
require APPPATH . '/libraries/REST_Controller.php';

/**
 * This is an example of a few basic user interaction methods you could use
 * all done with a hardcoded array
 *
 * @package         CodeIgniter
 * @subpackage      Rest Server
 * @category        Controller
 * @author          Hector Luna
 * @license         MIT
 * @link            https://github.com/chriskacerguis/codeigniter-restserver
 */
class Skol extends REST_Controller {

	function __construct() {
		header('Access-Control-Allow-Origin: *');
		header("Access-Control-Allow-Headers: Content-Type, Cache-Control");
		header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT");
		$method = $_SERVER['REQUEST_METHOD'];
		if($method == "OPTIONS") {
				die();
		}

		parent::__construct();
		$this->load->model('Md_skol');
		$this->load->library('form_validation');
	}

	public function categories_get() {
		$data = $this->Md_skol->getCategories();
		$this->set_response(['status' => TRUE, 'codigo' => 0, 'message' => 'Categorias', 'data' => $data], REST_Controller::HTTP_OK);
	}

	public function products_get() {
		$firebase = 0;
		$uid = $this->input->get('uid', TRUE);
		$firebase = $this->input->get('firebase', TRUE);

		if($uid) {
			$client = $this->Md_felix->getClient($uid,$firebase);
			if($client) {
				$this->set_response(['status' => TRUE, 'codigo' => 1, 'message' => 'Cliente', 'data' => $client], REST_Controller::HTTP_OK);
			} else $this->set_response(['status' => FALSE, 'codigo' => 0, 'message' => 'Cliente no encontrado', 'data' => array()], REST_Controller::HTTP_OK);
		} else $this->set_response(['status' => FALSE, 'codigo' => 0, 'message' => 'Faltan Parámetros', 'data' => array()], REST_Controller::HTTP_OK);
	}

}
