<?php
class Response
{
    public static function json($status, $message, $data = null, $code = 200)
    {
        header("Access-Control-Allow-Origin: *");
        header("Content-Type: application/json; charset=UTF-8");
        http_response_code($code);

        $response = [
            "status" => $status,
            "message" => $message
        ];

        if ($data !== null) {
            $response["data"] = $data;
        }

        echo json_encode($response);
        exit;
    }

    public static function success($message, $data = null)
    {
        self::json("success", $message, $data, 200);
    }

    public static function error($message, $code = 400, $data = null)
    {
        self::json("error", $message, $data, $code);
    }
}
?>