<?php

namespace App\Services\Payments;

use App\Enums\PaymentStatus;

/** Normalised view of an inbound provider webhook. */
class WebhookResult
{
    public function __construct(
        public readonly bool $valid,
        public readonly ?string $eventId = null,
        public readonly ?string $eventType = null,
        public readonly ?string $paymentReference = null,
        public readonly ?string $providerReference = null,
        public readonly ?PaymentStatus $status = null,
        public readonly ?float $amount = null,
        public readonly array $payload = [],
        public readonly ?string $error = null,
    ) {}

    public static function invalid(string $error, array $payload = []): self
    {
        return new self(false, error: $error, payload: $payload);
    }
}
