"""
This type stub file was generated by pyright.
"""

from collections.abc import Iterator
from contextlib import contextmanager
from dataclasses import dataclass
from typing import Optional, TYPE_CHECKING
from graph_sitter.core.autocommit.constants import AutoCommitState, AutoCommitSymbol
from graph_sitter.core.node_id_factory import NodeId
from graph_sitter.codebase.codebase_graph import CodebaseGraph
from graph_sitter.core.file import File

if TYPE_CHECKING:
    ...
logger = ...
@dataclass
class AutoCommitNode:
    """The pending update for a node.

    Attributes:
        symbol: The symbol being updated. Kept to ensure correctness
        generation: Version of the symbol
        new_id: New id to fetch (if applicable)
        new_file: File symbol was moved to (if applicable)
    """
    symbol: AutoCommitSymbol
    generation: int
    new_id: NodeId | None = ...
    new_file: Optional[File] = ...


@dataclass
class PendingFiles:
    """Current files autocommit is operating on.

    For example, if we read a symbol and find another symbol out of date in the same file, we would
    not want to update it.
    """
    files: set[str] | None
    all: bool = ...
    def __bool__(self) -> bool:
        ...
    


class AutoCommit:
    """Global autocommit state.

    Attributes:
        state: Current operation being performed
        _files: Mapping of files to their new filepaths, or None if they were just modified
        _nodes: Mapping of nodes to their new Node IDs
        _locked_files: All files that are currently being operated on
        _lock_all: All files are currently being operated on
    """
    state: AutoCommitState | None = ...
    _files: dict[NodeId, NodeId | None]
    _nodes: dict[NodeId, AutoCommitNode]
    G: CodebaseGraph
    _locked_files: set[str]
    _lock_all: bool = ...
    def __init__(self, G: CodebaseGraph) -> None:
        ...
    
    def __repr__(self) -> str:
        ...
    
    def check_update(self, node: AutoCommitSymbol, lock: PendingFiles, must_be_updated: bool = ...) -> None:
        """Check for an update to a node if possible."""
        ...
    
    def set_pending_file(self, file: AutoCommitSymbol, *, update_id: NodeId | None = ..., new_id: NodeId | None = ...) -> None:
        """Mark a file as pending."""
        ...
    
    def set_pending(self, node: AutoCommitSymbol, new_id: NodeId | None = ..., new_file: NodeId | None = ...) -> None:
        """Mark a node as pending.

        This also mark the file it's in, the file it's moved to, and it's parent if the node is
        detached
        """
        ...
    
    @contextmanager
    def write_state(self, node: AutoCommitSymbol, *, commit: bool = ..., move: bool = ...) -> Iterator[None]:
        """Enter a write state."""
        ...
    
    def enter_state(self, state: AutoCommitState) -> AutoCommitState | None:
        """Begin a new state."""
        ...
    
    @contextmanager
    def lock_files(self, files: set[str], all: bool = ..., commit: bool = ...) -> Iterator[PendingFiles]:
        ...
    
    def try_lock_files(self, files: set[str], all: bool = ..., commit: bool = ...) -> PendingFiles:
        ...
    
    def unlock_files(self, files: PendingFiles) -> None:
        ...
    
    def reset(self) -> None:
        """Reset Autocommit state.

        Probably not necessary
        """
        ...
    


