<?php
declare(strict_types=1);

namespace App\Core;

/**
 * Standardized JSON Response Helper
 */
class Response
{
    /**
     * Send success response
     */
    public static function success(mixed $data = [], string $message = 'Success', int $code = 200): void
    {
        header('Content-Type: application/json');
        http_response_code($code);
        echo json_encode([
            'success' => true,
            'data' => $data,
            'message' => $message,
            'errors' => null,
            'pagination' => null
        ], JSON_PRETTY_PRINT);
        exit;
    }

    /**
     * Send error response
     */
    public static function error(string $message = 'Error', array $errors = [], int $code = 400): void
    {
        header('Content-Type: application/json');
        http_response_code($code);
        echo json_encode([
            'success' => false,
            'data' => null,
            'message' => $message,
            'errors' => $errors,
            'pagination' => null
        ], JSON_PRETTY_PRINT);
        exit;
    }

    /**
     * Send paginated response
     */
    public static function paginated(array $data, int $total, int $page, int $perPage, string $message = 'Success'): void
    {
        header('Content-Type: application/json');
        http_response_code(200);
        $totalPages = (int) ceil($total / $perPage);
        echo json_encode([
            'success' => true,
            'data' => $data,
            'message' => $message,
            'errors' => null,
            'pagination' => [
                'page' => $page,
                'per_page' => $perPage,
                'total' => $total,
                'total_pages' => $totalPages
            ]
        ], JSON_PRETTY_PRINT);
        exit;
    }
}
