// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License

namespace Azure.Iot.Operations.Opc2Wot
{
    using System;
    using System.CommandLine;
    using System.IO;

    internal class Program
    {
        static void Main(string[] args)
        {
            var nodeSetsOption = new Option<string[]>("--nodeSets")
            {
                Description = "One or more glob patterns used to locate OPC UA Nodeset files to process",
                HelpName = "GLOB ...",
                Required = true,
                AllowMultipleArgumentsPerToken = true,
            };

            var outDirOption = new Option<DirectoryInfo>("--outDir")
            {
                Description = "Path to a folder for placing files that will each contain a collection of WoT Things",
                HelpName = "DIRPATH",
                Required = true,
            };

            var integrateOption = new Option<bool>("--integrate")
            {
                Description = "Integrate all referenced Thing Models into each Thing collection, making each output file self-contained",
            };

            var inheritVarsOption = new Option<bool>("--inheritVars")
            {
                Description = "Add a 'dov:includeInherited' property to root-level forms where appropriate, so that inherited variables are included in aggregate events and properties",
            };

            var includeTDsOption = new Option<bool>("--includeTDs")
            {
                Description = "Include Thing Descriptions, in addition to Thing Models, in the Thing collection",
            };

            var rootCommand = new RootCommand("Tool for converting OPC UA specs to WoT Thing Models and Thing Descriptions for use in Akri");
            rootCommand.Add(nodeSetsOption);
            rootCommand.Add(outDirOption);
            rootCommand.Add(integrateOption);
            rootCommand.Add(inheritVarsOption);
            rootCommand.Add(includeTDsOption);

            rootCommand.SetAction(parseResult =>
            {
                Environment.ExitCode = CommandHandler.ConvertSpecs(new OptionContainer
                {
                    NodeSetsSpec = parseResult.GetValue(nodeSetsOption)!,
                    OutputDir = parseResult.GetValue(outDirOption)!,
                    Integrate = parseResult.GetValue(integrateOption),
                    InheritVars = parseResult.GetValue(inheritVarsOption),
                    IncludeTDs = parseResult.GetValue(includeTDsOption),
                });
            });

            ParseResult parseResult = rootCommand.Parse(args);
            parseResult.Invoke();
        }
    }
}
