from dataclasses import dataclass
from enum import StrEnum

from ..router import Router, RouterType


class AliasType(StrEnum):
    HOST = "host"
    NETWORK = "network"
    PORT = "port"
    URL = "url"


@dataclass
class Alias:
    name: str
    alias_type: AliasType
    description: str
    content: list[str]
    detail: list[str]

    def __eq__(self, other):
        if not isinstance(other, Alias):
            return NotImplemented
        # Default equality comparison (all fields)
        return (
            self.name == other.name
            and self.alias_type == other.alias_type
            and self.description == other.description
            and self.content == other.content
            and self.detail == other.detail
        )

    def equals(self, other, router: Router):
        """
        Compare two Alias instances based on the Router type.

        :param other: The other Alias instance to compare with.
        :param router: The Router instance determining the comparison criteria.
        :return: True if aliases are equal based on the router type, False otherwise.
        """
        if not isinstance(other, Alias):
            return NotImplemented

        if router is None:
            raise ValueError("Router instance is required for equality comparison.")

        if not isinstance(router, Router):
            raise ValueError("Invalid Router instance provided.")

        # For both pfSenseV1 and pfSenseV2, compare all fields including 'detail'
        if router.type in (RouterType.PFSENSE_V1, RouterType.PFSENSE_V2):
            return (
                self.name == other.name
                and self.alias_type == other.alias_type
                and self.description == other.description
                and self.content == other.content
                and self.detail == other.detail
            )
        elif router.type == RouterType.OPNSENSE:
            # OPNsense does not support the 'detail' field
            return (
                self.name == other.name
                and self.alias_type == other.alias_type
                and self.description == other.description
                and self.content == other.content
            )
        else:
            raise ValueError("Unsupported Router type for comparison.")
