from ipaddress import (
    IPv4Interface,
    IPv4Network,
    IPv6Interface,
    IPv6Network,
)
from typing import TYPE_CHECKING, Any

import msgspec
from msgspec import Struct

if TYPE_CHECKING:
    IPNetwork = IPv4Network | IPv6Network
    IPInterface = IPv4Interface | IPv6Interface
else:
    from ipaddress import _BaseAddress as IPInterface  # type: ignore
    from ipaddress import _BaseNetwork as IPNetwork  # type: ignore


class TenantDTO(Struct):
    name: str


class NetboxPrefixDTO(Struct):
    description: str
    tenant: TenantDTO | None
    custom_fields: dict[str, Any]
    prefix: IPNetwork | None = msgspec.field(name="address", default=None)


class NetboxIPDTO(Struct):
    description: str
    address: IPInterface
    tenant: TenantDTO | None
    custom_fields: dict[str, Any]


class NetboxSubnetInfoDTO(Struct):
    ip_addresses: list[NetboxIPDTO]
    prefixes: list[NetboxPrefixDTO]
