using System.Collections.Generic;
using System.Threading.Tasks;
using CliFx;
using CliFx.Attributes;
using CliFx.Infrastructure;
using ZB.MOM.WW.GRAccess.Cli.GRAccess;
using ZB.MOM.WW.GRAccess.Cli.Infrastructure;

namespace ZB.MOM.WW.GRAccess.Cli.Commands.Objects
{
    [Command("object attributes", Description = "List attributes for a template or instance")]
    public class ObjectAttributesCommand : ICommand
    {
        [CommandOption("galaxy", 'g', Description = "Galaxy name", IsRequired = true)]
        public string GalaxyName { get; init; }

        [CommandOption("node", 'n', Description = "GR node name. Blank = local node; . = local machine")]
        public string NodeName { get; init; } = "";

        [CommandOption("name", Description = "Template or instance tagname", IsRequired = true)]
        public string ObjectName { get; init; }

        [CommandOption("type", 't', Description = "Object type: all, template, instance")]
        public string Type { get; init; } = "all";

        [CommandOption("configurable", Description = "List ConfigurableAttributes instead of all Attributes")]
        public bool ConfigurableOnly { get; init; }

        [CommandOption("json", Description = "Output as JSON")]
        public bool Json { get; init; }

        [CommandOption("llm-json", Description = "Output stable machine JSON envelope")]
        public bool LlmJson { get; init; }

        public async ValueTask ExecuteAsync(IConsole console)
        {
            var args = new Dictionary<string, object>
            {
                ["name"] = ObjectName,
                ["type"] = Type,
                ["configurable"] = ConfigurableOnly.ToString(),
                ["json"] = Json.ToString(),
                ["llm-json"] = LlmJson
            };

            await CommandRouter.ExecuteAsync(
                    console,
                    GalaxyName,
                    NodeName,
                    "object",
                    "attributes",
                    args,
                    galaxy => GRAccessCommandDispatcher.Execute(galaxy, "object", "attributes", args))
                .ConfigureAwait(false);
        }
    }
}
