using JetBrains.Annotations;
using LLM.Editor.Data;
using LLM.Editor.Helper;
using UnityEngine;

namespace LLM.Editor.Commands
{
    // Parameters for this command
    [System.Serializable]
    public class DisplayMessageParams
    {
        public CommandOutcome outcome;
        public string message;
    }

    [UsedImplicitly]
    public class DisplayMessageCommand : ICommand
    {
        private readonly DisplayMessageParams _params;
        
        public DisplayMessageCommand(string jsonParams)
        {
            _params = jsonParams?.FromJson<DisplayMessageParams>();
        }

        public DisplayMessageCommand(DisplayMessageParams param)
        {
            _params = param;
        }

        public CommandOutcome Execute(CommandContext context)
        {
            if (_params == null || string.IsNullOrEmpty(_params.message))
            {
                Debug.LogError("[DisplayMessageCommand] Parameters are invalid or message is empty.");
                return CommandOutcome.Error;
            }
            if (_params.outcome == CommandOutcome.Success)
            {
                Debug.Log($"<color=green>[MCP]: {_params.message}</color>");
            }
            else
            {
                Debug.LogError($"<color=red>[MCP]: {_params.message}</color>");
            }
            return CommandOutcome.Success;
        }
    }
}