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

class Favorites extends CI_Controller {

    public function get_user_favs(){
        header('Content-Type: application/json');
		$this->load->model('Favorites_model');
		$productArray = [];
			if (is_null($this->Favorites_model->get_user_favs()))
				$productArray = ['code' => '99', 'message' => 'No Messages available!', 'data' => ''];
			else {
				$productArray = ['code' => '00', 'message' => 'All Messages Retrieved', 'data' => $this->Favorites_model->get_user_favs()];
			}
		header('Content-Type: application/json');
		echo json_encode($productArray);
	  } 
    

    public function get_user_favs_by_id(){
        $id = $_REQUEST['user_id'];
        $this->load->model('Favorites_model');
		$productArray = [];
			if (is_null($this->Favorites_model->get_user_favs_id($id)))
				$productArray = ['code' => '99', 'message' => 'No Messages available!', 'data' => ''];
			else {
				$productArray = ['code' => '00', 'message' => 'All Messages Retrieved', 'data' => $this->Favorites_model->get_user_favs_id($id)];
			}
		header('Content-Type: application/json');
		echo json_encode($productArray);
	  } 
    
     public function save_new_fav(){
        header('Content-Type: application/json');
        $this->load->model('Favorites_model');
        echo json_encode($this->Favorites_model->save_new_fav());
    } 
    
     public function delete_fav(){
        header('Content-Type: application/json');
        $this->load->model('Favorites_model');
        echo json_encode($this->Favorites_model->delete_fav());
    } 

    public function detect_method(){
        echo json_encode($this->input->server('REQUEST_METHOD'));
    }

}

?>