<?php

declare(strict_types=1);

namespace App\Framework\Discovery\Enhanced\ValueObjects;

/**
 * Component Type enumeration for discovery classification
 */
enum ComponentType: string
{
    case CONTROLLER = 'controller';
    case SERVICE = 'service';
    case REPOSITORY = 'repository';
    case MIDDLEWARE = 'middleware';
    case COMMAND = 'command';
    case EVENT = 'event';
    case EXCEPTION = 'exception';
    case VALUE_OBJECT = 'value_object';
    case INTERFACE = 'interface';
    case TRAIT = 'trait';
    case ENUM = 'enum';
    case FACTORY = 'factory';
    case BUILDER = 'builder';
    case DECORATOR = 'decorator';
    case ADAPTER = 'adapter';
    case UNKNOWN = 'unknown';

    /**
     * Get component type description
     */
    public function getDescription(): string
    {
        return match ($this) {
            self::CONTROLLER => 'HTTP request controller',
            self::SERVICE => 'Business logic service',
            self::REPOSITORY => 'Data access repository',
            self::MIDDLEWARE => 'HTTP middleware',
            self::COMMAND => 'Console command',
            self::EVENT => 'Domain event',
            self::EXCEPTION => 'Exception class',
            self::VALUE_OBJECT => 'Value object or DTO',
            self::INTERFACE => 'Interface contract',
            self::TRAIT => 'Reusable trait',
            self::ENUM => 'Enumeration',
            self::FACTORY => 'Object factory',
            self::BUILDER => 'Object builder',
            self::DECORATOR => 'Decorator pattern',
            self::ADAPTER => 'Adapter pattern',
            self::UNKNOWN => 'Unknown component type'
        };
    }

    /**
     * Get component weight for dependency analysis
     */
    public function getWeight(): float
    {
        return match ($this) {
            self::CONTROLLER => 1.5,
            self::SERVICE => 1.3,
            self::REPOSITORY => 1.2,
            self::MIDDLEWARE => 1.1,
            self::COMMAND => 1.0,
            self::EVENT => 0.8,
            self::FACTORY => 1.1,
            self::BUILDER => 1.0,
            self::DECORATOR => 0.9,
            self::ADAPTER => 0.9,
            self::VALUE_OBJECT => 0.7,
            self::INTERFACE => 0.6,
            self::TRAIT => 0.5,
            self::ENUM => 0.4,
            self::EXCEPTION => 0.3,
            self::UNKNOWN => 0.5
        };
    }

    /**
     * Get typical dependency patterns for this component type
     */
    public function getTypicalDependencies(): array
    {
        return match ($this) {
            self::CONTROLLER => ['service', 'repository', 'validator'],
            self::SERVICE => ['repository', 'event_dispatcher', 'value_object'],
            self::REPOSITORY => ['connection', 'entity_manager', 'cache'],
            self::MIDDLEWARE => ['request', 'response', 'next'],
            self::COMMAND => ['service', 'input', 'output'],
            self::EVENT => ['value_object'],
            self::FACTORY => ['configuration', 'dependencies'],
            self::BUILDER => ['value_object'],
            default => []
        };
    }

    /**
     * Check if this component type typically has dependencies
     */
    public function hasDependencies(): bool
    {
        return match ($this) {
            self::CONTROLLER,
            self::SERVICE,
            self::REPOSITORY,
            self::MIDDLEWARE,
            self::COMMAND,
            self::FACTORY => true,
            default => false
        };
    }

    /**
     * Get performance impact level
     */
    public function getPerformanceImpact(): string
    {
        return match ($this) {
            self::CONTROLLER => 'high',
            self::SERVICE => 'medium',
            self::REPOSITORY => 'high',
            self::MIDDLEWARE => 'medium',
            self::COMMAND => 'low',
            self::EVENT => 'low',
            default => 'very_low'
        };
    }
}
