from opn_api.client import OPNFirewallClient
from pyfsense_client.v1.client import PfSenseV1Client
from pyfsense_client.v2.client import PfSenseV2Client

from routers.router import Router

from .adapter.opnsense import OPNsenseAliasAdapter
from .adapter.pfsense_v1 import PFSenseV1AliasAdapter
from .adapter.pfsense_v2 import PFSenseV2AliasAdapter


def get_alias_adapter(router: Router):
    """
    Factory function to retrieve the appropriate alias adapter based on the router's client type.
    """
    client = router.client
    if isinstance(client, PfSenseV1Client):
        return PFSenseV1AliasAdapter(client)
    elif isinstance(client, OPNFirewallClient):
        return OPNsenseAliasAdapter(client)
    elif isinstance(client, PfSenseV2Client):
        return PFSenseV2AliasAdapter(client)
    else:
        raise ValueError(f"Unknown client type for router: {router}")
