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

from abc import abstractmethod
from functools import cached_property
from typing import Generic, Self, TYPE_CHECKING, TypeVar
from graph_sitter._proxy import proxy_property
from graph_sitter.core.autocommit import reader, writer
from graph_sitter.core.detached_symbols.function_call import FunctionCall
from graph_sitter.core.expressions import Expression
from graph_sitter.core.interfaces.editable import Editable
from graph_sitter.core.interfaces.importable import Importable
from graph_sitter.core.statements.statement import Statement
from graph_sitter.writer_decorators import apidoc, noapidoc
from graph_sitter.core.detached_symbols.code_block import CodeBlock

if TYPE_CHECKING:
    ...
TIfBlockStatement = TypeVar("TIfBlockStatement", bound="IfBlockStatement")
TCodeBlock = TypeVar("TCodeBlock", bound="CodeBlock")
@apidoc
class IfBlockStatement(Statement[TCodeBlock], Generic[TCodeBlock, TIfBlockStatement]):
    """Abstract representation of the if/elif/else statement block.
    For example, if there is a code block like:
    if condition1:
        block1
    elif condition2:
        block2
    else:
        block3
    This class represents the entire block, including the conditions and nested code blocks.

    Attributes:
        condition: The condition expression for the if block. None if the block is an else block.
        consequence_block: The code block that is executed if the condition is True.
    """
    statement_type = ...
    condition: Expression[Self] | None
    consequence_block: TCodeBlock
    _alternative_blocks: list[TIfBlockStatement] | None
    _main_if_block: TIfBlockStatement
    @property
    @reader
    def function_calls(self) -> list[FunctionCall]:
        """Returns all function calls within the if block statement and its alternative blocks.

        Collects all function calls from the if block's condition, consequence block, and any alternative blocks (elif/else)
        including their conditions and consequence blocks.

        Returns:
            list[FunctionCall]: A list of function call objects found within this if block statement and its alternative blocks.
        """
        ...
    
    @property
    @noapidoc
    def descendant_symbols(self) -> list[Importable]:
        ...
    
    @cached_property
    @reader
    def nested_code_blocks(self) -> list[TCodeBlock]:
        """Returns all nested code blocks within an if/elif/else statement block.

        Returns a list of all CodeBlocks that are part of the current if/elif/else statement block, including the main if block's consequence block
        and all alternative (elif/else) blocks' consequence blocks.

        Returns:
            list[TCodeBlock]: A list of CodeBlock objects representing all nested code blocks within the statement.
        """
        ...
    
    @property
    @abstractmethod
    def is_if_statement(self) -> bool:
        """Returns whether the current block is an if block.

        A property that checks if the current block within an if/elif/else statement chain is an if block.
        This includes the main if block but not elif or else blocks.

        Args:
            None

        Returns:
            bool: True if the current block is an if block, False if it is an elif or else block.
        """
        ...
    
    @property
    @abstractmethod
    def is_else_statement(self) -> bool:
        """Indicates if the current block is an else block in an if/else statement chain.

        This property checks whether the current block represents an 'else' branch in a control flow statement. It helps in identifying and handling else
        blocks differently from if/elif blocks, particularly when manipulating control flow structures.

        Returns:
            bool: True if the current block is an else block, False otherwise.
        """
        ...
    
    @property
    @abstractmethod
    def is_elif_statement(self) -> bool:
        """Indicates whether the current block is an elif block.

        A property that returns True if the current instance of IfBlockStatement is specifically an elif block, False for if or else blocks.

        Returns:
            bool: True if the current block is an elif block, False for if or else blocks.
        """
        ...
    
    @property
    @reader
    def alternative_blocks(self) -> list[TIfBlockStatement]:
        """Returns a list of alternative if/elif/else blocks for the current block.

        Gets the alternative blocks (elif/else blocks) based on the type of the current block:
        - For if blocks: returns all alternative blocks
        - For else blocks: returns empty list
        - For elif blocks: returns all subsequent alternative blocks in the main if block

        Returns:
            list[TIfBlockStatement]: A list of alternative if/elif/else blocks that are executed if the condition is False.
        """
        ...
    
    @proxy_property
    @reader
    def elif_statements(self) -> list[TIfBlockStatement]:
        """Returns all elif blocks within the if block.

        Gets all alternative blocks that are specifically elif blocks (i.e., excluding else blocks) from an if statement. Can be called on any if/elif/else block to get subsequent elif blocks.

        Note:
        This method can be called as both a property and a method. If used as a property, it is equivalent to invoking it without arguments.

        Returns:
            list[TIfBlockStatement]: A list of elif block statements. Empty list if no elif blocks exist.
        """
        ...
    
    @property
    @reader
    def else_statement(self) -> TIfBlockStatement | None:
        """Returns the else block within the if-statement.

        Gets the else block from the if-statement's alternative blocks if one exists. Only returns the else block, not elif blocks.

        Returns:
            TIfBlockStatement | None: The else block statement if it exists, None otherwise.
        """
        ...
    
    @writer
    def reduce_condition(self, bool_condition: bool, node: Editable | None = ...) -> None:
        """Simplifies a conditional block by reducing its condition to a boolean value.

        This method modifies the if/elif/else block structure based on the provided boolean value.
        When reducing to True, it unwraps the consequence block and adjusts subsequent elif/else blocks.
        When reducing to False, it handles different cases for elif statements and main if blocks.

        Args:
            bool_condition (bool): The boolean value to reduce the condition to.
                If True, unwraps the consequence block and adjusts alternative blocks.
                If False, removes or modifies the current block based on its type.

        Returns:
            None

        Raises:
            ValueError: If attempting to reduce a condition on an IfBlockStatement that doesn't have a condition
                (like an else block).
        """
        ...
    


