import enum
from dataclasses import dataclass
from typing import List, Optional


class HostAction(enum.Enum):
    close_connection = "closeConnection"


class LockStrategy(enum.Enum):
    default = "default"
    bmw_nrc_forbidden = "bmwNrcForbidden"
    none = "none"


class ActionKind(enum.Enum):
    host = "host"
    set_arbitration = "setArbitration"
    lock_all_other_ecus = "lockAllOtherECUs"
    override_reply_id = "overrideReplyId"
    unlock_all_other_ecus = "unlockAllOtherECUs"


@dataclass
class Action:
    kind: ActionKind
    request_id: Optional[int] = None
    reply_id: Optional[int] = None
    auxiliary_ids: Optional[List[int]] = None
    host_action: Optional[HostAction] = None
    lock_strategy: Optional[LockStrategy] = None

    @staticmethod
    def host(action: HostAction) -> "Action":
        return Action(kind=ActionKind.host, host_action=action)

    @staticmethod
    def set_arbitration(request_id: int, reply_id: int, auxiliary_ids: List[int]) -> "Action":
        return Action(
            kind=ActionKind.set_arbitration,
            request_id=request_id,
            reply_id=reply_id,
            auxiliary_ids=auxiliary_ids,
        )

    @staticmethod
    def lock_all_other_ecus(strategy: LockStrategy) -> "Action":
        return Action(kind=ActionKind.lock_all_other_ecus, lock_strategy=strategy)

    @staticmethod
    def override_reply_id(reply_id: int) -> "Action":
        return Action(kind=ActionKind.override_reply_id, reply_id=reply_id)

    @staticmethod
    def unlock_all_other_ecus() -> "Action":
        return Action(kind=ActionKind.unlock_all_other_ecus)
