# cspell:ignore ecmd
"""Utility functions used by adjacent tests."""

from typing import Any

from ansible_navigator.configuration_subsystem.definitions import SettingsEntry


def id_for_base(val: str) -> str:
    """Return an id for a param set.

    Args:
        val: The base param set

    Returns:
        The id
    """
    if val is None:
        return "no-base-params"
    if "editor-command" in val:
        return "long-base-params"
    if "ecmd" in val:
        return "short-base-params"
    return "unknown-base-params"


def id_for_name(val: SettingsEntry) -> str:
    """Return an id based on entry name.

    Args:
        val: The entry

    Returns:
        The id
    """
    if isinstance(val, SettingsEntry):
        return f"{val.name}"
    return ""


def config_post_process(expected: dict[str, Any], path: str) -> dict[str, Any]:
    """Perform custom post processing on the configuration.

    Args:
        expected: The expected configuration
        path: The path to the configuration

    Returns:
        The processed configuration
    """
    if path == "ansible-navigator.execution-environment.volume-mounts":
        parsed_volume_mounts = []
        volume_mounts = expected["ansible-navigator"]["execution-environment"]["volume-mounts"]
        for volume_mount in volume_mounts:
            mount_path = f"{volume_mount['src']}:{volume_mount['dest']}"
            if volume_mount.get("options"):
                mount_path += f":{volume_mount['options']}"
            parsed_volume_mounts.append(mount_path)
        expected["ansible-navigator"]["execution-environment"]["volume-mounts"] = (
            parsed_volume_mounts
        )

    return expected
