<?php
namespace App\Core;

class Response {
    public static function json(mixed $data, int $statusCode = 200): void {
        http_response_code($statusCode);
        header('Content-Type: application/json; charset=utf-8');
        echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        exit;
    }

    public static function redirect(string $url, int $statusCode = 302): void {
        http_response_code($statusCode);
        header("Location: {$url}");
        exit;
    }

    public static function error(string $message, int $statusCode = 400): void {
        self::json([
            'success' => false,
            'error'   => $message
        ], $statusCode);
    }

    public static function success(mixed $data = null, string $message = 'Success'): void {
        self::json([
            'success' => true,
            'message' => $message,
            'data'    => $data
        ], 200);
    }
}
