<?php
    // HEADERS
    header('Access-Control-Allow-Origin: *');
    header('Content-Type: application/json');
    header('Access-Control-Allow-Methods: POST');
    header('Access-Control-Allow-Headers: Access-Control-Allow-Headers,Content-Type,Access-Control-Allow-Methods, Authorization, X-Requested-With');
    
//if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    
    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 RAW POSTED DATA
    $data = json_decode(file_get_contents("php://input"));

    $usuario->nome = $data->nome;
    $usuario->senha = $data->senha;
    $usuario->permissao = $data->permissao;
    $usuario->usuario = $data->usuario;
    $usuario->bloqueado = $data->bloqueado;

    // CREATE POST
    if($usuario->create()){
        echo json_encode(array('message' => 'Post Created')
        );
    } else {
        echo json_encode(array('message' => 'Post Not Created')
        );
    }
//}