<?php
//errors
// declare(strict_types=1);


class Home extends Controller {

    private $currentModel;

    public function __construct()
    {
        $this->currentModel = $this->model('Main');
    }

    //if the URL api request is unsuccessful, this will run
    public function notFound() {
        echo json_encode(['error' => '404 - not found']);
            }

     public function verifyToken() {
        if(isset($GLOBALS['headers'] ['Authorization'])) {
            if(parent::verifyTokenUserType($GLOBALS['headers'] ['Authorization'], $_SERVER['REMOTE_ADDR']) === 'contact') {
                echo json_encode(true);
            } else if(parent::verifyTokenUserType($GLOBALS['headers'] ['Authorization'], $_SERVER['REMOTE_ADDR']) === 'user') {
                echo json_encode(true);
            } else {
                echo json_encode(false);
            }
        } else {
            echo json_encode(false);
        }


    }

    public function verifyUserToken()
    {
        if(isset($GLOBALS['headers']['Authorization'])) {
            if(parent::verifyTokenUserType($GLOBALS['headers']['Authorization'], $_SERVER['REMOTE_ADDR']) === 'user'){
                echo json_encode(true);
            }else{
                echo json_encode(false);
            }
        } else {
            echo json_encode(false);
        }
    }

    // every time a function is called from one of the contacts controllers it will first test this to make sure it is actually a student trying to use the function
    public function verifyContactToken()
    {
        if(isset($GLOBALS['headers']['Authorization'])) {
            if(parent::verifyTokenUserType($GLOBALS['headers']['Authorization'], $_SERVER['REMOTE_ADDR']) === 'contact'){
                echo json_encode(true);
            }else{
                echo json_encode(false);
            }
        } else {
            echo json_encode(false);
        }
    }



}