from judy_core.messages import GetModelConfig, GetTaskConfig, ModelConfig, TaskConfig
from tongcell.core import MessageContext, RoutedActor, message_handler


class Configuration(RoutedActor):
    def __init__(self, task_config: TaskConfig, model_config: ModelConfig):
        super().__init__()
        self._task_config = task_config
        self._model_config = model_config

    @message_handler()
    async def get_task_config(
        self, _: GetTaskConfig, ctx: MessageContext
    ) -> TaskConfig:
        return self._task_config

    @message_handler()
    async def get_configuration(
        self, _: GetModelConfig, ctx: MessageContext
    ) -> ModelConfig:
        from judy_core.agents.executor import Executor
        from judy_core.agents.verifier import Verifier

        model_config = self._model_config.model_copy()
        if ctx.envelope.sender.kind not in (Executor.actor_kind, Verifier.actor_kind):
            model_config.tools_definition = []
        return model_config
