"""Example scope chain resolver for Git issue references."""

from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from cleveragents.domain.contexts import (
        ScopeResolutionContext,
    )


class GitIssueResolver:
    """Example resolver for Git issue scope references."""

    def __init__(self, repo_path: str | None = None) -> None:
        """Initialize the resolver."""
        self.repo_path = repo_path or "."

    def resolve(
        self,
        scope: str,
        context: ScopeResolutionContext,
    ) -> list[str]:
        """Resolve a Git issue scope reference."""
        if not scope.startswith("issue:"):
            return []

        try:
            issue_id = scope[6:]
            if not issue_id:
                return []

            fragment_id = f"git_issue_{issue_id}"
            return [fragment_id]
        except Exception:
            return []


def create_git_issue_resolver() -> GitIssueResolver:
    """Factory function for creating a GitIssueResolver instance."""
    return GitIssueResolver()
