"""
Slack connection client using slack_sdk.
"""

from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError


class SlackClientError(Exception):
    pass


def get_client(token: str) -> WebClient:
    """Create a Slack WebClient with the given token."""
    return WebClient(token=token)


def test_auth(client: WebClient) -> dict:
    """Test authentication and return user/bot info."""
    try:
        response = client.auth_test()
        return {
            "ok": response["ok"],
            "user": response.get("user"),
            "user_id": response.get("user_id"),
            "team": response.get("team"),
            "team_id": response.get("team_id"),
        }
    except SlackApiError as e:
        raise SlackClientError(f"Auth failed: {e.response['error']}")
