"""
Directory authority information.

This file is auto-generated by scripts/update_authorities.py
Do not edit manually.
"""

import random
from dataclasses import dataclass


@dataclass
class DirectoryAuthority:
    """Directory authority information."""

    nickname: str
    ip: str
    dirport: int
    orport: int
    v3ident: str  # hex fingerprint
    ipv6_address: str | None = None

    @property
    def http_url(self) -> str:
        """Get base HTTP URL for directory requests."""
        return f"http://{self.ip}:{self.dirport}"

    @property
    def address(self) -> str:
        """Get formatted address string."""
        return f"{self.ip}:{self.dirport}"


DIRECTORY_AUTHORITIES = [
    DirectoryAuthority(
        nickname="moria1",
        ip="128.31.0.39",
        dirport=9231,
        orport=9201,
        v3ident="F533C81CEF0BC0267857C99B2F471ADF249FA232",
    ),
    DirectoryAuthority(
        nickname="tor26",
        ip="217.196.147.77",
        dirport=80,
        orport=443,
        v3ident="2F3DF9CA0E5D36F2685A2DA67184EB8DCB8CBA8C",
        ipv6_address="[2a02:16a8:662:2203::1]:443",
    ),
    DirectoryAuthority(
        nickname="dizum",
        ip="45.66.35.11",
        dirport=80,
        orport=443,
        v3ident="E8A9C45EDE6D711294FADF8E7951F4DE6CA56B58",
    ),
    DirectoryAuthority(
        nickname="gabelmoo",
        ip="131.188.40.189",
        dirport=80,
        orport=443,
        v3ident="ED03BB616EB2F60BEC80151114BB25CEF515B226",
        ipv6_address="[2001:638:a000:4140::ffff:189]:443",
    ),
    DirectoryAuthority(
        nickname="dannenberg",
        ip="193.23.244.244",
        dirport=80,
        orport=443,
        v3ident="0232AF901C31A04EE9848595AF9BB7620D4C5B2E",
        ipv6_address="[2001:678:558:1000::244]:443",
    ),
    DirectoryAuthority(
        nickname="maatuska",
        ip="171.25.193.9",
        dirport=443,
        orport=80,
        v3ident="49015F787433103580E3B66A1707A00E60F2D15B",
        ipv6_address="[2001:67c:289c::9]:80",
    ),
    DirectoryAuthority(
        nickname="longclaw",
        ip="199.58.81.140",
        dirport=80,
        orport=443,
        v3ident="23D15D965BC35114467363C165C4F724B64B4F66",
    ),
    DirectoryAuthority(
        nickname="bastet",
        ip="204.13.164.118",
        dirport=80,
        orport=443,
        v3ident="27102BC123E7AF1D4741AE047E160C91ADC76B21",
        ipv6_address="[2620:13:4000:6000::1000:118]:443",
    ),
    DirectoryAuthority(
        nickname="faravahar",
        ip="216.218.219.41",
        dirport=80,
        orport=443,
        v3ident="70849B868D606BAECFB6128C5E3D782029AA394F",
    ),
]


def get_authorities() -> list[DirectoryAuthority]:
    """Get list of directory authorities."""
    return DIRECTORY_AUTHORITIES


def get_authority_by_nickname(nickname: str) -> DirectoryAuthority | None:
    """Get directory authority by nickname (case-insensitive)."""
    for auth in DIRECTORY_AUTHORITIES:
        if auth.nickname.lower() == nickname.lower():
            return auth
    return None


def get_random_authority() -> DirectoryAuthority:
    """Get a random directory authority."""
    return random.choice(DIRECTORY_AUTHORITIES)


def get_shuffled_authorities() -> list[DirectoryAuthority]:
    """Get all directory authorities in random order."""
    authorities = list(DIRECTORY_AUTHORITIES)
    random.shuffle(authorities)
    return authorities
