#
#   Imandra Inc.
#
#   events.py
#

import datetime

from imandra.u.agents.code_logician.command import Command
from pydantic import BaseModel, Field

from ..modeling.task import ModelTask
from ..sketch.task import SketchChange, SketchChangeResult
from .cl_agent_state import CLResult
from .config import StratConfigUpdate, StratMode


class StrategyEvent(BaseModel):
    """
    Base class
    """

    time: datetime.datetime = Field(default_factory=datetime.datetime.now)


class RunOneshotEvent(StrategyEvent, BaseModel):
    """
    Make strategy run in one-shot mode
    """

    pass  # We dont really need anything here...


class StratParamUpdate(StrategyEvent, BaseModel):
    """
    Event that updates strategy parameters
    """

    param: StratConfigUpdate


class ChangeMode(StrategyEvent, BaseModel):
    """
    Changes the mode (Idle/Auto)
    """

    new_mode: StratMode


class CLResultEvent(StrategyEvent, BaseModel):
    """
    Result that is generated by the CL worker when it's done processing the result
    """

    result: CLResult


class ModelCLTaskEvent(StrategyEvent, BaseModel):
    """
    Request to perform a specific command for all the workers
    """

    rel_path: str
    cmd: Command


class AutoModeCLTaskEvent(StrategyEvent, BaseModel):
    """
    Model formalization task that's generated by the strategy in AUTO mode
    """

    task: ModelTask


class SketchChangeEvent(StrategyEvent, BaseModel):
    """
    Change event for Sketch
    """

    sketch_id: str
    change: SketchChange


class SketchChangeResultEvent(StrategyEvent, BaseModel):
    """
    Result of running ImandraX on the latest change to a sketch
    """

    sketch_id: str
    change_result: SketchChangeResult
