"""{{ display_name }} MCP server — generated by mcpify. Do not hand-edit."""

from __future__ import annotations

import base64

from ..auth_strategy import AuthConfig, AuthStrategy, Credentials
from ..errors import MissingCredentialsError


class BasicAuthStrategy(AuthStrategy):
    async def authenticate(self, config: AuthConfig) -> Credentials:
        username = config.get("username")
        password = config.get("password")
        if not username or not password:
            raise MissingCredentialsError("username, password")

        token = base64.b64encode(f"{username}:{password}".encode()).decode()
        return {
            "username": username,
            "password": password,
            "authorization_header": f"Basic {token}",
        }

    def validate_credentials(self, credentials: Credentials) -> bool:
        return "authorization_header" in credentials
