<?php

declare(strict_types=1);

namespace App\Framework\Cryptography;

/**
 * Key Pair Value Object
 *
 * Represents a cryptographic key pair consisting of a private and public key.
 */
final readonly class KeyPair
{
    public function __construct(
        private PrivateKey $privateKey,
        private PublicKey $publicKey
    ) {
    }

    /**
     * Get the private key
     */
    public function getPrivateKey(): PrivateKey
    {
        return $this->privateKey;
    }

    /**
     * Get the public key
     */
    public function getPublicKey(): PublicKey
    {
        return $this->publicKey;
    }

    /**
     * Get key algorithm
     */
    public function getAlgorithm(): string
    {
        return $this->privateKey->getAlgorithm();
    }

    /**
     * Get key size in bits
     */
    public function getKeySize(): int
    {
        return $this->privateKey->getKeySize();
    }

    /**
     * Get curve name (ECDSA only)
     */
    public function getCurve(): ?string
    {
        return $this->privateKey->getCurve();
    }

    /**
     * Check if this is an RSA key pair
     */
    public function isRsa(): bool
    {
        return $this->privateKey->isRsa();
    }

    /**
     * Check if this is an ECDSA key pair
     */
    public function isEcdsa(): bool
    {
        return $this->privateKey->isEcdsa();
    }

    /**
     * Export both keys to array
     * @return array<string, array<string, mixed>>
     */
    public function toArray(): array
    {
        return [
            'private_key' => $this->privateKey->toArray(),
            'public_key' => $this->publicKey->toArray(),
        ];
    }

    /**
     * Get key pair summary (safe for logging)
     * @return array<string, mixed>
     */
    public function getSummary(): array
    {
        return [
            'algorithm' => $this->getAlgorithm(),
            'key_size' => $this->getKeySize(),
            'curve' => $this->getCurve(),
            'private_key_present' => true,
            'public_key_present' => true,
        ];
    }
}
