from typing import Any, List, Optional, Union

from dev.coatl.helper.types import AnyStr as AnyStr
from java.lang import Comparable, Enum, Object
from org.apache.poi.ss import SpreadsheetVersion
from org.apache.poi.ss.formula.eval import ValueEval
from org.apache.poi.ss.formula.functions import FreeRefFunction, Function
from org.apache.poi.ss.formula.ptg import (
    Area3DPtg,
    Area3DPxg,
    NamePtg,
    NameXPtg,
    NameXPxg,
    Ptg,
    Ref3DPtg,
    Ref3DPxg,
)
from org.apache.poi.ss.formula.udf import UDFFinder
from org.apache.poi.ss.usermodel import (
    Cell,
    CellType,
    ConditionalFormatting,
    ConditionalFormattingRule,
    ConditionType,
    ExcelNumberFormat,
    Sheet,
    Workbook,
)
from org.apache.poi.ss.util import CellRangeAddress, CellRangeAddressBase, CellReference

class EvaluationCell:
    def getArrayFormulaRange(self) -> CellRangeAddress: ...
    def getBooleanCellValue(self) -> bool: ...
    def getCacheFormulaResultType(self) -> CellType: ...
    def getCellType(self) -> CellType: ...
    def getColumnIndex(self) -> int: ...
    def getErrorCellValue(self) -> int: ...
    def getIdentityKey(self) -> Object: ...
    def getNumericCellValue(self) -> float: ...
    def getRowIndex(self) -> int: ...
    def getSheet(self) -> EvaluationSheet: ...
    def getStringCellValue(self) -> AnyStr: ...
    def isPartOfArrayFormulaGroup(self) -> bool: ...

class EvaluationSheet:
    def clearAllCachedResultValues(self) -> None: ...
    def getCell(self, rowIndex: int, columnIndex: int) -> EvaluationCell: ...
    def getLastRowNum(self) -> int: ...
    def isRowHidden(self, rowIndex: int) -> bool: ...

class EvaluationWorkbook:
    class ExternalName(Object):
        def __init__(self, nameName: AnyStr, nameNumber: int, ix: int) -> None: ...
        def getIx(self) -> int: ...
        def getNameName(self) -> AnyStr: ...
        def getNameNumber(self) -> int: ...

    class ExternalSheet(Object):
        def __init__(self, workbookName: AnyStr, sheetName: AnyStr) -> None: ...
        def getSheetName(self) -> AnyStr: ...
        def getWorkbookName(self) -> AnyStr: ...

    class ExternalSheetRange(Object):
        def __init__(
            self, workbookName: AnyStr, firstSheetName: AnyStr, lastSheetName: AnyStr
        ) -> None: ...
        def getFirstSheetName(self) -> AnyStr: ...
        def getLastSheetName(self) -> AnyStr: ...

    def clearAllCachedResultValues(self) -> None: ...
    def convertFromExternSheetIndex(self, externSheetIndex: int) -> int: ...
    def getExternalName(
        self,
        externSheetIndex: int,
        sheetName: int,
        externalWorkbookNumber: Optional[int] = ...,
    ) -> ExternalName: ...
    def getExternalSheet(self, *args: Any) -> ExternalSheet: ...
    def getFormulaTokens(self, cell: EvaluationCell) -> List[Ptg]: ...
    def getName(
        self, name: Union[AnyStr, NamePtg], sheetIndex: Optional[int] = ...
    ) -> ExternalName: ...
    def getSheet(self, sheetIndex: int) -> EvaluationSheet: ...
    def getSheetIndex(self, arg: Union[AnyStr, EvaluationSheet]) -> int: ...
    def getSheetName(self, sheetIndex: int) -> AnyStr: ...
    def getSpreadsheetVersion(self) -> SpreadsheetVersion: ...
    def getUDFFinder(self) -> UDFFinder: ...
    def resolveNameXText(self, ptg: NameXPtg) -> AnyStr: ...

class EvaluationCache(Object):
    def clear(self) -> None: ...
    def getOrCreateFormulaCellEntry(
        self, cell: EvaluationCell
    ) -> FormulaCellCacheEntry: ...
    def getPlainValueEntry(
        self,
        bookIndex: int,
        sheetIndex: int,
        rowIndex: int,
        columnIndex: int,
        value: ValueEval,
    ) -> PlainValueCellCacheEntry: ...
    def notifyDeleteCell(
        self, bookIndex: int, sheetIndex: int, cell: EvaluationCell
    ) -> None: ...
    def notifyUpdateCell(
        self, bookIndex: int, sheetIndex: int, cell: EvaluationCell
    ) -> None: ...

class EvaluationTracker(Object):
    def __init__(self, cache: EvaluationCache) -> None: ...
    def acceptFormulaDependency(self, cce: CellCacheEntry) -> None: ...
    def acceptPlainValueDependency(
        self,
        bookIndex: int,
        sheetIndex: int,
        rowIndex: int,
        columnIndex: int,
        value: ValueEval,
    ) -> None: ...
    def endEvaluate(self, cce: CellCacheEntry) -> None: ...
    def startEvaluate(self, cce: FormulaCellCacheEntry) -> bool: ...
    def updateCacheResult(self, result: ValueEval) -> int: ...

class IEvaluationListener:
    class ICacheEntry:
        def getValue(self) -> ValueEval: ...

    def onCacheHit(self, var1: int, var2: int, var3: int, var4: ValueEval) -> None: ...
    def onReadPlainValue(
        self, var1: int, var2: int, var3: int, var4: ICacheEntry
    ) -> None: ...
    def onStartEvaluate(self, var1: EvaluationCell, var2: ICacheEntry) -> None: ...
    def onClearWholeCache(self) -> None: ...
    def onClearCachedValue(self, var1: ICacheEntry) -> None: ...
    def sortDependentCachedValues(self, var1: List[ICacheEntry]) -> None: ...
    def onClearDependentCachedValues(self, var1: ICacheEntry, var2: int) -> None: ...
    def onChangeFromBlankValue(
        self, var1: int, var2: int, var3: int, var4: ValueEval, var5: ICacheEntry
    ) -> None: ...

class CellCacheEntry(Object, IEvaluationListener.ICacheEntry):
    def addConsumingCell(self, cellLoc: FormulaCellCacheEntry) -> None: ...
    def clearConsumingCell(self, cce: FormulaCellCacheEntry) -> None: ...
    def getConsumingCells(self) -> List[FormulaCellCacheEntry]: ...
    def getValue(self) -> ValueEval: ...
    def recurseClearCachedFormulaResults(
        self, listener: IEvaluationListener
    ) -> None: ...
    def updateValue(self, value: ValueEval) -> None: ...

class ExternSheetReferenceToken:
    def format2DRefAsString(self) -> AnyStr: ...
    def getExternSheetIndex(self) -> int: ...

class FormulaCellCacheEntry(CellCacheEntry):
    def __init__(self) -> None: ...
    def addConsumingCell(self, cellLoc: FormulaCellCacheEntry) -> None: ...
    def changeConsumingCells(self, usedCells: List[CellCacheEntry]) -> None: ...
    def clearFormulaEntry(self) -> None: ...
    def getConsumingCells(self) -> List[FormulaCellCacheEntry]: ...
    def getValue(self) -> ValueEval: ...
    def isInputSensitive(self) -> bool: ...
    def notifyUpdatedBlankCell(
        self,
        bsj: int,
        rowIndex: int,
        columnIndex: int,
        evaluationListener: IEvaluationListener,
    ) -> None: ...
    def recurseClearCachedFormulaResults(
        self, listener: IEvaluationListener
    ) -> None: ...
    def setSensitiveInputCells(
        self, sensitiveInputCells: List[CellCacheEntry]
    ) -> None: ...
    def updateFormulaResult(
        self,
        result: ValueEval,
        sensitiveInputCells: List[CellCacheEntry],
        usedBlankAreas: FormulaUsedBlankCellSet,
    ) -> None: ...
    def updateValue(self, value: ValueEval) -> None: ...

class FormulaUsedBlankCellSet(Object):
    class BlankCellRectangleGroup(Object):
        def __init__(
            self, firstRowIndex: int, firstColumnIndex: int, lastColumnIndex: int
        ) -> None: ...
        def containsCell(self, rowIndex: int, columnIndex: int) -> bool: ...
        def acceptRow(
            self, rowIndex: int, firstColumnIndex: int, lastColumnIndex: int
        ) -> bool: ...

    class BlankCellSheetGroup(Object):
        def __init__(self, lastDefinedRow: int) -> None: ...
        def addCell(self, rowIndex: int, columnIndex: int) -> None: ...
        def containsCell(self, rowIndex: int, columnIndex: int) -> bool: ...

    class BookSheetKey(Object):
        def __init__(self, bookIndex: int, sheetIndex: int) -> None: ...

    def addCell(
        self,
        evalWorkbook: EvaluationWorkbook,
        bookIndex: int,
        sheetIndex: int,
        rowIndex: int,
        columnIndex: int,
    ) -> None: ...
    def getSheetGroup(
        self, evalWorkbook: EvaluationWorkbook, bookIndex: int, sheetIndex: int
    ) -> BlankCellSheetGroup: ...
    def containsCell(
        self, key: BookSheetKey, rowIndex: int, columnIndex: int
    ) -> bool: ...
    def isEmpty(self) -> bool: ...

class PlainValueCellCacheEntry(CellCacheEntry):
    def __init__(self, value: ValueEval) -> None: ...
    def addConsumingCell(self, cellLoc: FormulaCellCacheEntry) -> None: ...
    def clearConsumingCell(self, cce: FormulaCellCacheEntry) -> None: ...
    def getConsumingCells(self) -> List[FormulaCellCacheEntry]: ...
    def getValue(self) -> ValueEval: ...
    def recurseClearCachedFormulaResults(
        self, listener: IEvaluationListener
    ) -> None: ...
    def updateValue(self, value: ValueEval) -> None: ...

class SheetRange:
    def getFirstSheetIndex(self) -> int: ...
    def getLastSheetIndex(self) -> int: ...

class SheetRefEvaluator(Object):
    def __init__(
        self,
        bookEvaluator: WorkbookEvaluator,
        tracker: EvaluationTracker,
        sheetIndex: int,
    ) -> None: ...
    def getEvalForCell(self, rowIndex: int, columnIndex: int) -> ValueEval: ...
    def getSheet(self) -> EvaluationSheet: ...
    def getSheetName(self) -> AnyStr: ...
    def isSubTotal(self, rowIndex: int, columnIndex: int) -> bool: ...
    def isRowHidden(self, rowIndex: int) -> bool: ...

class SheetRangeEvaluator(Object, SheetRange):
    def __init__(
        self,
        firstSheetIndex: int,
        lastSheetIndex: int,
        sheetEvaluators: List[SheetRefEvaluator],
    ) -> None: ...
    def getEvalForCell(
        self, sheetIndex: int, rowIndex: int, columnIndex: int
    ) -> ValueEval: ...
    def getFirstSheetIndex(self) -> int: ...
    def getLastSheetIndex(self) -> int: ...
    def getSheetEvaluator(self, sheetIndex: int) -> SheetRefEvaluator: ...
    def getSheetName(self, sheetIndex: int) -> AnyStr: ...
    def getSheetNameRange(self) -> AnyStr: ...

class OperationEvaluationContext(Object):
    UDF: FreeRefFunction
    def __init__(
        self,
        bookEvaluator: WorkbookEvaluator,
        workbook: EvaluationWorkbook,
        sheetIndex: int,
        srcRowNum: int,
        srcColNum: int,
        tracker: EvaluationTracker,
        isSingleValue: bool = ...,
    ) -> None: ...
    def findUserDefinedFunction(self, name: AnyStr) -> FreeRefFunction: ...
    def getArea3DEval(self, aptg: Union[Area3DPtg, Area3DPxg]) -> ValueEval: ...
    def getAreaEval(
        self,
        firstRowIndex: int,
        firstColumnIndex: int,
        lastRowIndex: int,
        lastColumnIndex: int,
    ) -> ValueEval: ...
    def getAreaValueEval(
        self,
        firstRowIndex: int,
        firstColumnIndex: int,
        lastRowIndex: int,
        lastColumnIndex: int,
        tokens: List[Object],
    ) -> ValueEval: ...
    def getColumnIndex(self) -> int: ...
    def getDynamicReference(
        self,
        workbookName: AnyStr,
        sheetName: AnyStr,
        refStrPart1: AnyStr,
        refStrPart2: AnyStr,
        isA1Style: bool,
    ) -> ValueEval: ...
    def getNameXEval(self, arg: Union[NameXPtg, NameXPxg]) -> ValueEval: ...
    def getRef3DEval(self, arg: Union[Ref3DPtg, Ref3DPxg]) -> ValueEval: ...
    def getRefEval(self, rowIndex: int, colIndex: int) -> ValueEval: ...
    def getRefEvaluatorForCurrentSheet(self) -> SheetRangeEvaluator: ...
    def getRowIndex(self) -> int: ...
    def getSheetIndex(self) -> int: ...
    def getWorkbook(self) -> EvaluationWorkbook: ...
    def isArrayMode(self) -> bool: ...
    def isSingleValue(self) -> bool: ...
    def setArrayMode(self, value: bool) -> None: ...

class IStabilityClassifier:
    TOTALLY_IMMUTABLE: IStabilityClassifier
    def isCellFinal(self, sheetIndex: int, rowIndex: int, columnIndex: int) -> bool: ...

class WorkbookDependentFormula:
    def toFormulaString(self) -> AnyStr: ...

class WorkbookEvaluator(Object):
    def __init__(
        self,
        workbook: EvaluationWorkbook,
        stabilityClassifier: IStabilityClassifier,
        udfFinder: UDFFinder,
    ) -> None: ...
    def clearAllCachedResultValues(self) -> None: ...
    @staticmethod
    def dereferenceResult(
        evaluationResult: ValueEval, srcRowNum: int, srcColNum: int
    ) -> ValueEval: ...
    def evaluate(self, *args: Any) -> ValueEval: ...
    def evaluateList(
        self, formula: AnyStr, target: CellReference, region: CellRangeAddressBase
    ) -> ValueEval: ...
    def findUserDefinedFunction(self, name: AnyStr) -> FreeRefFunction: ...
    @staticmethod
    def getNotSupportedFunctionNames() -> List[AnyStr]: ...
    @staticmethod
    def getSupportedFunctionNames() -> List[AnyStr]: ...
    def isDebugEvaluationOutpotForNextEval(self) -> bool: ...
    def isIgnoreMissingWorkbooks(self) -> bool: ...
    def notifyDeleteCell(self, cell: EvaluationCell) -> None: ...
    def notifyUpdateCell(self, cell: EvaluationCell) -> None: ...
    @staticmethod
    def registerFunction(
        name: AnyStr, func: Union[FreeRefFunction, Function]
    ) -> None: ...
    def setDebugEvaluationOutputForNextEval(self, value: bool) -> None: ...
    def setIgnoreMissingWorkbooks(self, ignore: bool) -> None: ...

class WorkbookEvaluatorProvider: ...

class EvaluationConditionalFormatRule(Object, Comparable):
    class OperatorEnum(Enum):
        BETWEEN: EvaluationConditionalFormatRule.OperatorEnum
        EQUAL: EvaluationConditionalFormatRule.OperatorEnum
        GREATER_OR_EQUAL: EvaluationConditionalFormatRule.OperatorEnum
        GREATER_THAN: EvaluationConditionalFormatRule.OperatorEnum
        LESS_OR_EQUAL: EvaluationConditionalFormatRule.OperatorEnum
        LESS_THAN: EvaluationConditionalFormatRule.OperatorEnum
        NO_COMPARISON: EvaluationConditionalFormatRule.OperatorEnum
        NOT_BETWEEN: EvaluationConditionalFormatRule.OperatorEnum
        NOT_EQUAL: EvaluationConditionalFormatRule.OperatorEnum
        def isValid(self, *args: Comparable) -> bool: ...
        def isValidForCompatibleTypes(self) -> bool: ...
        @staticmethod
        def values() -> List[EvaluationConditionalFormatRule.OperatorEnum]: ...

    def __init__(
        self,
        workbookEvaluator: WorkbookEvaluator,
        sheet: Sheet,
        formatting: ConditionalFormatting,
        formattingIndex: int,
        rule: ConditionalFormattingRule,
        ruleIndex: int,
        regions: List[CellRangeAddress],
    ) -> None: ...
    def compareTo(self, o: Any) -> int: ...
    def getFormatting(self) -> ConditionalFormatting: ...
    def getFormattingIndex(self) -> int: ...
    def getFormula1(self) -> AnyStr: ...
    def getFormula2(self) -> AnyStr: ...
    def getNumberFormat(self) -> ExcelNumberFormat: ...
    def getOperator(self) -> EvaluationConditionalFormatRule.OperatorEnum: ...
    def getPriority(self) -> int: ...
    def getRegions(self) -> List[CellRangeAddress]: ...
    def getRule(self) -> ConditionalFormattingRule: ...
    def getRuleIndex(self) -> int: ...
    def getSheet(self) -> Sheet: ...
    def getText(self) -> AnyStr: ...
    def getType(self) -> ConditionType: ...

class ConditionalFormattingEvaluator(Object):
    def __init__(self, wb: Workbook, provider: WorkbookEvaluatorProvider) -> None: ...
    def clearAllCachedFormats(self) -> None: ...
    def clearAllCachedValues(self) -> None: ...
    def getConditionalFormattingForCell(
        self, cell: Union[Cell, CellReference]
    ) -> List[EvaluationConditionalFormatRule]: ...
    def getFormatRulesForSheet(
        self, sheet: Union[AnyStr, Sheet]
    ) -> List[EvaluationConditionalFormatRule]: ...
    def getMatchingCells(self, *args: Any) -> List[Cell]: ...
    @staticmethod
    def getRef(cell: Cell) -> CellReference: ...
