from __future__ import annotations

#import panel as pn

from typing import List
from pydantic import Field, root_validator
#from abipy.abio.inputs import AbinitInput
#from abipy.panels.core import ply
#from abipy.panels.viewers import JSONViewer
#from abipy.flowtk import TaskManager, Flow
from .base_models import MongoConnector  # , GfsFileDesc
from .flow_models import FlowModel, PresetQuery



class GbrvFlowModel(FlowModel):

    #scf_input: AbinitInput = Field(None, description="Abinit Input file generated by AbiPy.")

    ########
    # Output
    ########

    #scf_data: ScfData = Field(None, description="Results produced by the SCF run.")

    def build_flow(self, workdir: str, worker: AbipyWorker) -> Flow:
        """
        Build an AbiPy Flow in workdir using the input data available in the model and return it.
        """
        pseudos = self.pseudos_specs.get_pseudos()
        #return flow

    def postprocess_flow(self, flow: Flow, mng_connector: MongoConnector) -> None:
        """
        Analyze the flow and fills the model with output results.
        MongoConnector should be used only to insert files in GridFs as the final insertion is done by the caller.
        This function is called by the AbiPy Worker if the flow completed successfully.
        """

    def get_panel_view(self, mng_connector: MongoConnector):
        """
        Return panel object with a view of the model.
        """

    @classmethod
    def get_preset_queries(cls) -> List[PresetQuery]:
        """
        Return list of dictionaries with the MongoDB queries typically used to filter documents for this model.
        Empty list if no suggestion is available.
        """
        #return [
        #    PresetQuery(
        #        query={"$or": [
        #            {"scf_data.abs_pressure_gpa": {"$gt": p_gpa}},
        #            {"scf_data.max_force_ev_over_ang": {"$gt": 1e-4}}]
        #        },
        #        projection=["in_structure_data.formula_pretty",
        #                    "scf_data.abs_pressure_gpa", "scf_data.max_force_ev_over_ang",
        #                   ],
        #        info=f"Filter `{cls.__name__}` documents with pressure > {p_gpa} GPa "
        #             f"or absolute max force > {max_force} eV/Ang",
        #        )
        #]

