<?php
namespace Api\Core;

class Response {
    public function json($data, $status = 200) {
        http_response_code($status);
        header('Content-Type: application/json');
        echo json_encode($data);
        exit;
    }

    public function unauthorized(?string $data = null) {
        http_response_code(401);
        header('Content-Type: application/json');
        header('HTTP/1.1 401 Unauthorized');
        header('Content-Length: 0');
        if ($data !== null && $data !== '') {
            echo json_encode($data);
        }
        exit;
    }
}
