from __future__ import annotations

PINNED_VERSION = "0.14.0"

CHECKSUMS: dict[str, dict[str, str]] = {
    "0.14.0": {
        "linux_amd64": "placeholder_amd64_checksum_to_be_filled",
        "linux_arm64": "placeholder_arm64_checksum_to_be_filled",
    },
}


def get_checksum(version: str, arch: str) -> str:
    return CHECKSUMS[version][arch]


def binary_url(version: str, arch: str, override: str | None = None) -> str:
    if override:
        return override
    return (
        f"https://github.com/canyonroad/agentsh/releases/download/"
        f"v{version}/agentsh_{version}_{arch}.tar.gz"
    )


def build_verify_command(binary_path: str, expected_checksum: str) -> str:
    """Build a shell command to verify SHA256 checksum of a file."""
    import shlex

    safe_path = shlex.quote(binary_path)
    safe_checksum = shlex.quote(expected_checksum)
    return (
        f"echo {safe_checksum}  {safe_path} | "
        f"sha256sum -c --status 2>/dev/null || "
        f"echo {safe_checksum}  {safe_path} | "
        f"shasum -a 256 -c --status 2>/dev/null || "
        f'test "$(openssl dgst -sha256 -r {safe_path} | cut -d\' \' -f1)" = {safe_checksum}'
    )
