<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

use Restserver\Libraries\REST_Controller;

defined('BASEPATH') or exit('No direct script access allowed');
require APPPATH . 'libraries/REST_Controller.php';
require APPPATH . 'libraries/Format.php';
class Api extends REST_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->library('form_validation');
        // $this->load->library('session');
        // $this->load->model('user_model');
        $this->load->model('common');
        // $this->load->helper(array('form', 'url', 'string'));
    }

    public function allreminders_get($id)
    {
        $reminders = $this->common->readdatafromcollectionwhereclause("Reminders", "user_id", "=", $id);
        $response = array();
        if ($reminders) {
            $this->response($reminders, REST_Controller::HTTP_OK);
        } else {
            $this->response([
                'status' => FALSE,
                'message' => 'no reminders found'
            ], REST_Controller::HTTP_NOT_FOUND);
        }
    }

    public function todaysreminders_get($id)
    {
        $time = time();
        $reminders = $this->common->readdatafromcollectionbetween("Reminders", "user_id", "=", $id, "timestamp", ">", $time, "timestamp", "<", $time + 86400);
        $response = array();
        if ($reminders) {
            $this->response($reminders, REST_Controller::HTTP_OK);
        } else {
            $this->response([
                'status' => FALSE,
                'message' => 'no reminders found'
            ], REST_Controller::HTTP_NOT_FOUND);
        }
    }

    public function weeksreminders_get($id)
    {
        $time = time();
        $reminders = $this->common->readdatafromcollectionbetween("Reminders", "user_id", "=", $id, "timestamp", ">", $time, "timestamp", "<", $time + 604800);
        $response = array();
        if ($reminders) {
            $this->response($reminders, REST_Controller::HTTP_OK);
        } else {
            $this->response([
                'status' => FALSE,
                'message' => 'no reminders found'
            ], REST_Controller::HTTP_NOT_FOUND);
        }
    }

    // public function getuser_get()
    // {
    //     $id = $this->get('id');
    // $customer = $this->common->readdatadocument("Users", $id);
    //     $response = array();
    //     if ($customer) {
    //         $response['success'] = TRUE;
    //         $response['data'] = $customer;
    //     } else {
    //         $response['success'] = FALSE;
    //         $response['error'] = 'Error! Something went wrong. Please retry.';
    //     }
    //     echo (json_encode($response));
    // }

    // public function adduser_post()
    // {
    //     $data = $this->post();
    //     $customer = $this->customer_model->add_customer($data);
    //     $response = array();
    //     if ($customer) {
    //         $response['success'] = TRUE;
    //         $response['data'] = $customer;
    //     } else {
    //         $response['success'] = FALSE;
    //         $response['error'] = 'Error! Something went wrong. Please retry.';
    //     }
    //     echo (json_encode($response));
    // }

    // public function updateuser_patch()
    // {
    //     $userid = $this->patch('id');
    //     $data = $this->patch('data');
    //     $this->customer_model->update_customerpassword($id, $da['password']);
    //     $response = array();
    //     $customer = $this->common->updatedatamodel("Users", $userid, $data);
    //     if ($customer) {
    //         $response['success'] = TRUE;
    //         $response['data'] = $customer;
    //     } else {
    //         $response['success'] = FALSE;
    //         $response['error'] = 'Error! Something went wrong. Please retry.';
    //     }
    //     echo (json_encode($response));
    // }

    // public function deleteuser_delete()
    // {
    //     $userid = $this->delete('id');
    //     $response = array();
    //     $flag = $this->customer_model->delete_customer($userid);
    //     if ($flag) {
    //         $this->common->deletedatamodel("Users", $id);
    //         $response['success'] = TRUE;
    //         $response['data'] = $id;
    //     } else {
    //         $response['success'] = FALSE;
    //         $response['error'] = 'Error! Something went wrong. Please retry.';
    //     }
    //     echo (json_encode($response));
    // }

    public function index()
    {
        // $resp = array('status' => 1, 'message' => 'All ok');
        // $this->set_response($resp);
        echo "ok";
    }
}
