from typing import Callable, List, Any, Optional

from NonameOrm.DB.DB import DB
from NonameOrm.DB.Generator import SqlGenerator
from NonameOrm.Model.DataModel import InstanceList, ModelInstance, DataModel
from NonameOrm.Model.ModelProperty import BaseProperty, FilterListCell


class BaseModelExecutor:
    sql: SqlGenerator
    model: DataModel
    db: DB
    work: Any

    def __init__(self, model: DataModel, work=None): ...

    def instanceToFilter(self, instance: ModelInstance): ...

    def reset(self) -> BaseModelExecutor: ...

    @property
    def generator(self) -> SqlGenerator: ...

    def findAnyMatch(self, instance: ModelInstance, limit=None, offset=0): ...

    def find(self, *cols: List[BaseProperty]): ...

    def save(self, instance: ModelInstance): ...

    def update(self, instance: ModelInstance): ...

    def editSql(self, callback: Callable[[SqlGenerator], None]) -> BaseModelExecutor: ...

    def execute(self): ...

    def process(self, res): ...


class AsyncModelExecutor(BaseModelExecutor):

    async def findAnyMatch(self, instance: ModelInstance, limit=None, offset=0) -> List: ...

    async def findAllBy(self, Filter: FilterListCell = None): ...

    def find(self, *cols: List[BaseProperty]) -> AsyncModelExecutor: ...

    async def By(self, Fileter: FilterListCell) -> ModelInstance: ...

    async def save(self, instance: ModelInstance): ...

    async def update(self, instance: ModelInstance): ...

    async def execute(self) -> ModelInstance: ...

    async def findForeignKey(self, instance, deep: Optional[bool] = False): ...

    async def findListForeignKey(self, instances: InstanceList, deep: Optional[bool] = False):...
