<?php

declare(strict_types=1);

namespace App\Framework\Core\ValueObjects;

/**
 * Link Validation Result Value Object
 *
 * Represents the result of link validation with errors and warnings.
 *
 * @psalm-immutable
 */
final readonly class LinkValidationResult
{
    /**
     * @param bool $isValid Whether link is valid
     * @param array<string> $errors Critical validation errors
     * @param array<string> $warnings Non-critical warnings
     * @param array<string> $suggestions Improvement suggestions
     */
    public function __construct(
        public bool $isValid,
        public array $errors = [],
        public array $warnings = [],
        public array $suggestions = [],
    ) {}

    /**
     * Create valid result
     */
    public static function valid(?array $suggestions = null): self
    {
        return new self(
            isValid: true,
            suggestions: $suggestions ?? []
        );
    }

    /**
     * Create invalid result
     */
    public static function invalid(array $errors, ?array $warnings = null): self
    {
        return new self(
            isValid: false,
            errors: $errors,
            warnings: $warnings ?? []
        );
    }

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

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

    /**
     * Check if result has suggestions
     */
    public function hasSuggestions(): bool
    {
        return !empty($this->suggestions);
    }

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

    /**
     * Get total issue count
     */
    public function getIssueCount(): int
    {
        return count($this->errors) + count($this->warnings);
    }

    /**
     * Convert to array for logging
     */
    public function toArray(): array
    {
        return [
            'is_valid' => $this->isValid,
            'errors' => $this->errors,
            'warnings' => $this->warnings,
            'suggestions' => $this->suggestions,
            'error_count' => count($this->errors),
            'warning_count' => count($this->warnings),
        ];
    }
}
