from __future__ import annotations

from dataclasses import dataclass


@dataclass(frozen=True)
class Addressing:
    mode: str
    id: int
    reply: int = 0
    request_extension: int = 0
    reply_extension: int = 0

    @staticmethod
    def unicast(identifier: int, reply: int, request_extension: int = 0, reply_extension: int = 0) -> "Addressing":
        return Addressing(mode="unicast", id=identifier, reply=reply, request_extension=request_extension, reply_extension=reply_extension)

    @staticmethod
    def id_only(identifier: int, extension: int = 0) -> "Addressing":
        return Addressing(mode="id", id=identifier, request_extension=extension)

    @staticmethod
    def unset() -> "Addressing":
        return Addressing(mode="unset", id=0)

    @property
    def is_extended(self) -> bool:
        return self.request_extension != 0

    @property
    def request_extension_optional(self) -> int | None:
        return self.request_extension if self.request_extension != 0 else None
