<?php
// ─── Savuki Drilling — Response Helper ───────────────────────────────────

class Response {

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

    public static function error(string $message, int $status = 400, mixed $data = null): never {
        self::send($status, ['success' => false, 'message' => $message, 'data' => $data]);
    }

    private static function send(int $status, array $body): never {
        http_response_code($status);
        header('Content-Type: application/json');
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
        header('Access-Control-Allow-Headers: Content-Type');
        if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') exit;
        echo json_encode($body, JSON_UNESCAPED_UNICODE);
        exit;
    }
}
