<?php

    // HEADERS
    header('Access-Control-Allow-Origin: *');
    header('Content-Type: application/json');
    header('Access-Control-Allow-Headers: Access-Control-Allow-Headers,Content-Type,Access-Control-Allow-Methods, Authorization, X-Requested-With');
    
//if ($_SERVER['REQUEST_METHOD'] == 'GET') {

    include_once '../../config/Database.php';
    include_once '../../models/Usuario.php';

    // INSTANTIATE DB AND CONNECT
    $database = new Database();
    $db = $database->connect();

    // INSTANTIATE POST OBJECT
    $usuario = new Usuario($db);

    // GET ID
    $usuario->id = isset($_GET['id']) ? $_GET['id'] : die();

    // GET POST
    $usuario->read_single();

    // CREATE ARRAY
    $usuario_arr = array(
        'id' => $usuario->id,
        'usuario' => $usuario->usuario,
        'senha' => $usuario->senha,
        'permissao' => $usuario->permissao,
        'bloqueado' => $usuario->bloqueado,
        'nome' => $usuario->nome
    );

    // MAKE JSON
    print_r(json_encode($usuario_arr));
//}