<?php

declare(strict_types=1);

namespace App\Framework\Totp;

/**
 * TOTP Configuration Validation Result
 *
 * Value object containing validation results for TOTP configuration parameters.
 */
final readonly class TotpConfigurationValidation
{
    public function __construct(
        public bool $isValid,
        public array $errors,
        public array $warnings,
        public array $recommendedChanges
    ) {
    }

    /**
     * Check if configuration has any errors
     */
    public function hasErrors(): bool
    {
        return ! empty($this->errors);
    }

    /**
     * Check if configuration has any warnings
     */
    public function hasWarnings(): bool
    {
        return ! empty($this->warnings);
    }

    /**
     * Check if configuration has recommendations
     */
    public function hasRecommendations(): bool
    {
        return ! empty($this->recommendedChanges);
    }

    /**
     * Get all issues (errors and warnings combined)
     */
    public function getAllIssues(): array
    {
        return array_merge($this->errors, $this->warnings);
    }

    /**
     * Get validation summary
     */
    public function getSummary(): string
    {
        if ($this->isValid) {
            if ($this->hasWarnings()) {
                return 'Configuration is valid but has ' . count($this->warnings) . ' warnings';
            }

            return 'Configuration is valid';
        }

        return 'Configuration is invalid: ' . implode(', ', $this->errors);
    }

    /**
     * Convert to array for API responses
     */
    public function toArray(): array
    {
        return [
            'is_valid' => $this->isValid,
            'errors' => $this->errors,
            'warnings' => $this->warnings,
            'recommended_changes' => $this->recommendedChanges,
            'has_errors' => $this->hasErrors(),
            'has_warnings' => $this->hasWarnings(),
            'has_recommendations' => $this->hasRecommendations(),
            'summary' => $this->getSummary(),
        ];
    }
}
