"""Type stubs for rshogi.core — core primitives for shogi."""

from __future__ import annotations

from typing import Any

from rshogi.svg import Svg
from rshogi.types import (
    Bitboard,
    Color,
    Hand,
    MoveType,
    Piece,
    PieceType,
    RepetitionState,
    Square,
)


class Move:
    MOVE_NONE: Move
    MOVE_NULL: Move
    MOVE_RESIGN: Move
    MOVE_WIN: Move
    MOVE_END: Move
    def __init__(self, value: int) -> None: ...
    @classmethod
    def from_usi(cls, usi: str) -> Move: ...
    def to_usi(self) -> str: ...
    def is_drop(self) -> bool: ...
    def is_promotion(self) -> bool: ...
    def is_normal(self) -> bool: ...
    @property
    def from_sq(self) -> Square: ...
    @property
    def to_sq(self) -> Square: ...
    @property
    def dropped_piece_type(self) -> PieceType | None: ...
    @property
    def move_type(self) -> MoveType: ...
    @property
    def value(self) -> int: ...
    def to_apery(self) -> AperyMove: ...
    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 Move32:
    MOVE_NONE: Move32
    MOVE_NULL: Move32
    MOVE_RESIGN: Move32
    MOVE_WIN: Move32
    MOVE_END: Move32
    def __init__(self, value: int) -> None: ...
    @classmethod
    def from_usi(cls, usi: str) -> Move32: ...
    def to_usi(self) -> str: ...
    def is_drop(self) -> bool: ...
    def is_promotion(self) -> bool: ...
    def is_normal(self) -> bool: ...
    @property
    def from_sq(self) -> Square: ...
    @property
    def to_sq(self) -> Square: ...
    @property
    def dropped_piece_type(self) -> PieceType | None: ...
    @property
    def move_type(self) -> MoveType: ...
    @property
    def piece_after_move(self) -> Piece: ...
    @property
    def value(self) -> int: ...
    def to_move(self) -> Move: ...
    def to_apery(self, board: Board) -> AperyMove32: ...
    def to_csa(self) -> str | None: ...
    def to_ki2(self, board: Board) -> str | None: ...
    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 AperyMove:
    def __init__(self, value: int) -> None: ...
    @classmethod
    def from_usi(cls, usi: str) -> AperyMove: ...
    def to_usi(self) -> str: ...
    def to_move(self) -> Move: ...
    def is_drop(self) -> bool: ...
    def is_promotion(self) -> bool: ...
    def is_normal(self) -> bool: ...
    @property
    def from_sq(self) -> Square: ...
    @property
    def to_sq(self) -> Square: ...
    @property
    def dropped_piece_type(self) -> PieceType | None: ...
    @property
    def move_type(self) -> MoveType: ...
    @property
    def value(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 AperyMove32:
    def __init__(self, value: int) -> None: ...
    def to_usi(self) -> str: ...
    def to_move(self) -> Move: ...
    def to_move32(self, board: Board) -> Move32: ...
    def to_apery_move(self) -> AperyMove: ...
    def is_drop(self) -> bool: ...
    def is_promotion(self) -> bool: ...
    def is_capture(self) -> bool: ...
    def is_normal(self) -> bool: ...
    @property
    def from_sq(self) -> Square: ...
    @property
    def to_sq(self) -> Square: ...
    @property
    def dropped_piece_type(self) -> PieceType | None: ...
    @property
    def move_type(self) -> MoveType: ...
    @property
    def piece_type_before(self) -> PieceType: ...
    @property
    def piece_type_after(self) -> PieceType: ...
    @property
    def captured_piece_type(self) -> PieceType: ...
    @property
    def value(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 ValidationIssue:
    @property
    def kind(self) -> str: ...
    @property
    def color(self) -> Color | None: ...
    @property
    def file_usi(self) -> str | None: ...
    @property
    def square(self) -> Square | None: ...
    @property
    def piece_type(self) -> PieceType | None: ...
    @property
    def count(self) -> int | None: ...
    @property
    def message(self) -> str: ...
    def __eq__(self, other: object) -> bool: ...
    def __ne__(self, other: object) -> bool: ...
    def __repr__(self) -> str: ...
    def __str__(self) -> str: ...


class ValidationReport:
    def is_valid(self) -> bool: ...
    @property
    def issues(self) -> list[ValidationIssue]: ...
    def __len__(self) -> int: ...
    def __eq__(self, other: object) -> bool: ...
    def __ne__(self, other: object) -> bool: ...
    def __repr__(self) -> str: ...


class PositionState:
    def __init__(self, sfen: str | None = ...) -> None: ...
    @classmethod
    def from_sfen(cls, sfen: str) -> PositionState: ...
    def copy(self) -> PositionState: ...
    def __copy__(self) -> PositionState: ...
    def to_sfen(self, include_ply: bool = ...) -> str: ...
    def piece_on(self, square: Square) -> Piece: ...
    def set_piece(self, square: Square, piece: Piece) -> None: ...
    def hand(self, color: Color) -> Hand: ...
    def set_hand(self, color: Color, hand: Hand) -> None: ...
    def validate(self) -> None: ...
    def is_valid(self) -> bool: ...
    def validate_all(self) -> ValidationReport: ...
    @property
    def side_to_move(self) -> Color: ...
    @side_to_move.setter
    def side_to_move(self, color: Color) -> None: ...
    @property
    def ply(self) -> int: ...
    @ply.setter
    def ply(self, ply: int) -> None: ...
    @property
    def board(self) -> list[Piece]: ...
    @property
    def hands(self) -> tuple[Hand, Hand]: ...
    def __eq__(self, other: object) -> bool: ...
    def __ne__(self, other: object) -> bool: ...
    def __repr__(self) -> str: ...


class Board:
    def __init__(self, sfen: str | None = ...) -> None: ...
    def to_sfen(self) -> str: ...
    def to_position_state(self) -> PositionState: ...
    def copy(self) -> Board: ...
    def __copy__(self) -> Board: ...
    def to_packed_sfen(self, out: Any | None = ...) -> Any: ...
    def to_hcp(self, out: Any | None = ...) -> Any: ...
    def to_psv(
        self,
        mv: Any | None = ...,
        score: int = ...,
        game_result: Any | None = ...,
        game_ply: int | None = ...,
        out: Any | None = ...,
    ) -> Any: ...
    def to_hcpe(
        self,
        best_move: Any | None = ...,
        score: int = ...,
        game_result: Any | None = ...,
        out: Any | None = ...,
    ) -> Any: ...
    def set_sfen(self, sfen: str) -> None: ...
    def set_position_state(self, state: PositionState) -> None: ...
    def set_usi_position(self, position: str) -> None: ...
    def set_packed_sfen(self, psfen: bytes | bytearray | Any) -> None: ...
    def set_hcp(self, hcp: bytes | bytearray | Any, game_ply: int = ...) -> None: ...
    def zobrist_hash(self) -> int: ...
    def can_declare_win(self) -> bool: ...
    def move32_from_move(self, mv: Move) -> Move32: ...
    def apery_move32_from_move(self, mv: Move) -> AperyMove32: ...
    def apery_move32_from_move32(self, mv: Move32) -> AperyMove32: ...
    def move_from_csa(self, csa: str) -> Move32: ...
    def apply_move(self, move: Move) -> None: ...
    def apply_move32(self, move: Move32) -> None: ...
    def push_move(self, move: Move) -> Move32: ...
    def push_move32(self, move: Move32) -> Move32: ...
    def apply_usi(self, usi: str) -> None: ...
    def push_usi(self, usi: str) -> Move32: ...
    def apply_csa(self, csa: str) -> None: ...
    def undo_move(self, move: Move) -> None: ...
    def undo_move32(self, move: Move32) -> None: ...
    def pop(self) -> Move32 | None: ...
    def last_move(self) -> Move32 | None: ...
    def piece_on(self, square: Square) -> Piece: ...
    def is_square_empty(self, square: Square) -> bool: ...
    def empties(self) -> Bitboard: ...
    def hand(self, color: Color) -> Hand: ...
    def king_square(self, color: Color) -> Square: ...
    @property
    def turn(self) -> Color: ...
    @property
    def game_ply(self) -> int: ...
    def pieces(self) -> Bitboard: ...
    def pieces_by_type(self, piece_type: PieceType) -> Bitboard: ...
    def pieces_by_color(self, color: Color) -> Bitboard: ...
    def pieces_for(self, piece_type: PieceType, color: Color) -> Bitboard: ...
    def golds(self) -> Bitboard: ...
    def bishop_horse(self) -> Bitboard: ...
    def rook_dragon(self) -> Bitboard: ...
    def attackers_to(self, square: Square, occupied: Bitboard) -> Bitboard: ...
    def attackers_to_color(self, color: Color, square: Square, occupied: Bitboard) -> Bitboard: ...
    def attackers_to_color_current(self, color: Color, square: Square) -> Bitboard: ...
    def is_attacked_by(self, square: Square, by_color: Color) -> bool: ...
    def attacks_by(self, color: Color, piece_type: PieceType) -> Bitboard: ...
    def is_legal_move(self, move: Move) -> bool: ...
    def is_legal_move32(self, move: Move32) -> bool: ...
    def legal_moves(self) -> list[Move]: ...
    def legal_moves_full(self) -> list[Move32]: ...
    def pseudo_legal_moves(self) -> list[Move]: ...
    def pseudo_legal_moves_full(self) -> list[Move32]: ...
    def is_in_check(self) -> bool: ...
    def is_mated(self) -> bool: ...
    def validate(self) -> None: ...
    def is_valid(self) -> bool: ...
    def validate_all(self) -> ValidationReport: ...
    def repetition_state(self) -> RepetitionState: ...
    def is_repetition(self, threshold: int = ...) -> bool: ...
    def to_svg(self, last_move: Move | Move32 | None = ..., scale: float = ...) -> Svg: ...
    def to_bod(self) -> str: ...
    def to_csa(self) -> str: ...
    def reset(self) -> None: ...


def to_move(move: Move | Move32 | int) -> Move: ...
def parse_usi_position(position: str) -> Board: ...
def normalize_usi_position(position: str) -> str: ...


__all__ = [
    "AperyMove",
    "AperyMove32",
    "Board",
    "Move32",
    "Move",
    "PositionState",
    "ValidationIssue",
    "ValidationReport",
    "to_move",
    "parse_usi_position",
    "normalize_usi_position",
]
