"""Factory that resolves the C2Adapter implementation from MIMIC_C2_ADAPTER env."""
from __future__ import annotations

import os

from backend.app.services.c2.adapter import C2Adapter


def get_adapter(url: str, api_token: str, verify_tls: bool = False) -> C2Adapter:
    """Return the correct C2Adapter based on MIMIC_C2_ADAPTER (default: mythic)."""
    adapter_name = os.environ.get("MIMIC_C2_ADAPTER", "mythic").lower()

    if adapter_name == "fake":
        from backend.app.services.c2.fake import FakeAdapter
        return FakeAdapter()

    # Default: real Mythic adapter
    from backend.app.services.c2.mythic import MythicAdapter
    return MythicAdapter(url=url, api_token=api_token, verify_tls=verify_tls)
