<?php

namespace App\Support;

use Illuminate\Http\JsonResponse;

class ApiError
{
    public static function response(
        string $code,
        string $title,
        string $message,
        int $status,
        array $meta = []
    ): JsonResponse {
        $payload = [
            'error' => [
                'code' => $code,
                'title' => $title,
                'message' => $message,
            ],
        ];

        if ($meta !== []) {
            $payload['error']['meta'] = $meta;
        }

        return response()->json($payload, $status);
    }
}
