"""Type stubs for rshogi.book — opening book types for shogi."""

from __future__ import annotations

from rshogi.core import Board, Move, Move32
from rshogi.record import GameRecord


class BookKey:
    @property
    def low(self) -> int: ...
    @property
    def high(self) -> int: ...
    def __int__(self) -> int: ...
    def __hash__(self) -> int: ...
    def __eq__(self, other: object) -> bool: ...
    def __ne__(self, other: object) -> bool: ...
    def __repr__(self) -> str: ...
    def __str__(self) -> str: ...


class BookMove:
    def __init__(self, mv: Move, score: int, depth: int) -> None: ...
    @property
    def mv(self) -> Move: ...
    @property
    def score(self) -> int: ...
    @property
    def depth(self) -> int: ...
    def __repr__(self) -> str: ...
    def __str__(self) -> str: ...


class BookEntry:
    @property
    def key(self) -> BookKey: ...
    @property
    def moves(self) -> list[BookMove]: ...
    def __len__(self) -> int: ...
    def __repr__(self) -> str: ...


class MemoryBook:
    def __init__(self) -> None: ...
    def insert_move(self, key: BookKey, book_move: BookMove) -> None: ...
    def get(self, key: BookKey) -> BookEntry | None: ...
    def contains(self, key: BookKey) -> bool: ...
    def __len__(self) -> int: ...
    def __repr__(self) -> str: ...


class StaticBook:
    @classmethod
    def from_bytes(cls, data: bytes | bytearray) -> StaticBook: ...
    @classmethod
    def from_memory_book(cls, book: MemoryBook) -> StaticBook: ...
    @classmethod
    def from_file(cls, path: str) -> StaticBook: ...
    def to_bytes(self) -> bytes: ...
    def write_file(self, path: str) -> None: ...
    def get(self, key: BookKey) -> BookEntry | None: ...
    def contains(self, key: BookKey) -> bool: ...
    def __len__(self) -> int: ...
    def __repr__(self) -> str: ...


class BookBuilder:
    def __init__(self) -> None: ...
    def insert(self, key: BookKey, mv: Move, score: int, depth: int) -> None: ...
    def insert_for_position(self, board: Board, mv: Move, score: int, depth: int) -> None: ...
    def extend_from_game_record(
        self,
        record: GameRecord,
        default_score: int = ...,
        default_depth: int = ...,
    ) -> None: ...
    def into_memory(self) -> MemoryBook: ...
    def build_static(self) -> StaticBook: ...
    def __repr__(self) -> str: ...


def book_key_from_position(board: Board) -> BookKey: ...
def book_key_after(board: Board, mv: Move) -> BookKey: ...
def book_builder_from_game_record(
    record: GameRecord,
    default_score: int = ...,
    default_depth: int = ...,
) -> MemoryBook: ...


__all__ = [
    "BookKey",
    "BookMove",
    "BookEntry",
    "MemoryBook",
    "StaticBook",
    "BookBuilder",
    "book_key_from_position",
    "book_key_after",
    "book_builder_from_game_record",
]
