<?php

declare(strict_types=1);

namespace App\Framework\Security\RequestSigning;

/**
 * Result of request signature verification
 */
final readonly class VerificationResult
{
    private function __construct(
        public bool $isValid,
        public ?string $errorMessage = null,
        public ?RequestSignature $signature = null,
        public ?SigningKey $key = null,
    ) {
    }

    /**
     * Create a successful verification result
     */
    public static function success(RequestSignature $signature, SigningKey $key): self
    {
        return new self(
            isValid: true,
            signature: $signature,
            key: $key,
        );
    }

    /**
     * Create a failed verification result
     */
    public static function failure(string $errorMessage): self
    {
        return new self(
            isValid: false,
            errorMessage: $errorMessage,
        );
    }

    /**
     * Check if verification was successful
     */
    public function isSuccess(): bool
    {
        return $this->isValid;
    }

    /**
     * Check if verification failed
     */
    public function isFailure(): bool
    {
        return ! $this->isValid;
    }
}
