<?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
/** @noinspection PhpIncludeInspection */
require __DIR__.'/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          Phil Sturgeon, Chris Kacerguis
 * @license         MIT
 * @link            https://github.com/chriskacerguis/codeigniter-restserver
 */
class Packages_activate extends REST_Controller
{
    public function __construct()
    {
        // Construct the parent class
        parent::__construct();
    }

    public function data_get($id_package = null)
    {
        //$id_package = (int)$id_package;

          /*if($id_package == null OR $id_package == 0){
            $this->response([
                'status' => false,
                'message' => 'No package specified'
            ], REST_Controller::HTTP_NOT_FOUND);
            $data['status'] = false;
          }*/

          $this->load->library('app_modules');

          $slug  = null;
          if($id_package == 1){
            $slug = 'startup_package';
          }else if($id_package == 2){
            $slug = 'essential_package';
          }else if($id_package == 3){
            $slug = 'pro_package';
          }else{
            $this->response([
                'status' => false,
                'message' => 'No package found with ID '.$id_package
            ], REST_Controller::HTTP_NOT_FOUND);
            $data['status'] = false;
          }


          $this->app_modules->deactivate('startup_package');
          $this->app_modules->deactivate('essential_package');
          $this->app_modules->deactivate('pro_package');
          if($id_package != 1){

          }else if($id_package != 2){

          }else if($id_package != 3){

          }

          if($slug != null){
            $this->app_modules->activate($slug);
            $data['status'] = $this->module_model->is_active($slug);
            if(!$data['status']){
              $data['message'] = 'Module could not be activated.';
            }
          }else{
            $data['status'] = true;
            $data['message'] = 'All packages deactivated.';
          }

        if ($data) {
            $this->response($data, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
        } else {
            // Set the response and exit
            $this->response([
                'status' => false,
                'message' => 'No data were found'
            ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
        }
    }



	public function activate($id_package = null){
    if($id_package == null){ return false; }
		$this->load->library('app_modules');
		if($id_package == 1){
			$slug = 'startup_package';
		}else if($id_package == 1){
			$slug = 'essential_package';
		}else if($id_package == 1){
			$slug = 'pro_package';
		}else{
			return false;
		}
		$this->app_modules->activate($slug);
		return true;
	}

}
