<?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 Stihl 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_stihl');
	}

	public function categories_get()
	{
		$data = $this->Md_stihl->putCategories();

		$this->set_response(['status' => TRUE, 'codigo' => 1, 'message' => '', 'data' => $data], REST_Controller::HTTP_OK);
	}

	public function descuentos_get()
	{
		$data = $this->Md_stihl->putDescuentos();

		$this->set_response(['status' => TRUE, 'codigo' => 1, 'message' => '', 'data' => $data], REST_Controller::HTTP_OK);
	}

	public function products_get()
	{
		$data = $this->Md_stihl->putProducts();

		$this->set_response(['status' => TRUE, 'codigo' => 1, 'message' => '', 'data' => $data], REST_Controller::HTTP_OK);
	}

	
	public function test_get()
	{
		$sku = $this->get('sku');
		$data = $this->Md_stihl->getProduct($sku);
		if(!empty($data)) $this->set_response(['status' => TRUE, 'codigo' => 1, 'message' => 'Product', 'data' => $data], REST_Controller::HTTP_OK);
		else $this->set_response(['status' => FALSE, 'codigo' => 0, 'message' => 'Product', 'data' => array()], REST_Controller::HTTP_OK);
		
	}


}
