"""Slack user identity mapping for Autopilot approvals."""

from __future__ import annotations

import json
from pathlib import Path
from typing import Any, Dict


def _mapping_path(state_dir: Path) -> Path:
    return Path(state_dir) / "slack_users.json"


def load_slack_user_map(state_dir: Path) -> Dict[str, Dict[str, Any]]:
    path = _mapping_path(state_dir)
    if not path.exists():
        return {}
    with open(path, encoding="utf-8") as f:
        return json.load(f) or {}


def map_slack_user(slack_user_id: str, state_dir: Path) -> Dict[str, Any] | None:
    mapping = load_slack_user_map(state_dir)
    return mapping.get(slack_user_id)


__all__ = ["load_slack_user_map", "map_slack_user"]
