#!/usr/bin/env python
import sys
from predictive_potential_engine.crew import PredictivePotentialEngineCrew

# Replace with your child's real observations before a real run.

def _sample_inputs():
    return {
        "child_name": "Jesse",
        "child_age": "9",
        "obs_hours": (
            "Builds elaborate structures out of anything — couch cushions, scrap "
            "wood, lego. Spent a whole weekend digging a drainage channel in the "
            "yard after it rained."
        ),
        "obs_trouble": (
            "Took apart the remote and the toaster to see inside. Ruins good "
            "clothes playing in the mud. Won't come in for dinner mid-project."
        ),
        "obs_questions": "How bridges hold up. Why the basement floods. How engines work.",
        "obs_play": "Organizes the other kids into building crews and assigns jobs.",
        "obs_adults": "Teachers say Jesse is stubborn but finishes everything they start.",
        "obs_favorites": "toolbox, dump trucks, minecraft, the hardware store, rain",
    }


def run():
    """Run the crew."""
    PredictivePotentialEngineCrew().crew().kickoff(inputs=_sample_inputs())


def train():
    """Train the crew for a given number of iterations."""
    try:
        PredictivePotentialEngineCrew().crew().train(
            n_iterations=int(sys.argv[1]), filename=sys.argv[2], inputs=_sample_inputs()
        )
    except Exception as e:
        raise Exception(f"An error occurred while training the crew: {e}")


def replay():
    """Replay the crew execution from a specific task."""
    try:
        PredictivePotentialEngineCrew().crew().replay(task_id=sys.argv[1])
    except Exception as e:
        raise Exception(f"An error occurred while replaying the crew: {e}")


def test():
    """Test the crew execution and return the results."""
    try:
        PredictivePotentialEngineCrew().crew().test(
            n_iterations=int(sys.argv[1]),
            openai_model_name=sys.argv[2],
            inputs=_sample_inputs(),
        )
    except Exception as e:
        raise Exception(f"An error occurred while testing the crew: {e}")
