from inspect_ai.tool import Tool, tool

from ._rxnwrapper import RXNRetroSynthesis
from .name2smiles import NAME2SMILES_DICT


@tool
def rxnplanner(summarize_model_name: str) -> Tool:
    rxn_retrosynthesis = RXNRetroSynthesis(summarize_model_name)
    async def execute(target_smiles: str):
        """
        Plan a synthesis of the target molecule, given its SMILES notation.

        Args:
            target_smiles: The SMILES notation of the target molecule
        
        Returns:
            A plan for the synthesis of the target molecule.
        """
        if target_smiles not in set(NAME2SMILES_DICT.values()):
            return "Invalid SMILES. Please use name2smiles tool to get a valid SMILES."
        output = await rxn_retrosynthesis.run(target_smiles)
        return output

    return execute
