<?php

namespace Modules\Payment\Exceptions;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Modules\Payment\Enums\PaymentMethod;
use RuntimeException;

/**
 * Thrown by a gateway's handleWebhook() when the inbound payload's signature
 * doesn't check out — never let an unverified webhook be treated as genuine
 * (domain.md §6).
 */
class InvalidWebhookSignatureException extends RuntimeException
{
    public static function forGateway(PaymentMethod $method): self
    {
        return new self("Webhook signature verification failed for gateway [{$method->value}].");
    }

    public function render(Request $request): ?JsonResponse
    {
        return response()->json(['message' => $this->getMessage()], 400);
    }
}
