using System.Collections.Generic;
using AIRuntime.Runtime.Capabilities;
using AIRuntime.Runtime.Providers.Models;

namespace AIRuntime.Runtime.Providers
{
    public interface IProviderToolBuilder
    {
        IReadOnlyList<ProviderTool> Build(
            IReadOnlyCollection<ICapability> capabilities);
    }


    public sealed class ProviderToolBuilder :
        IProviderToolBuilder
    {
        private readonly CapabilitySchemaExporter _exporter;


        public ProviderToolBuilder()
        {
            _exporter =
                new CapabilitySchemaExporter();
        }


        public IReadOnlyList<ProviderTool> Build(
            IReadOnlyCollection<ICapability> capabilities)
        {
            List<ProviderTool> tools =
                new List<ProviderTool>();


            foreach(ICapability capability in capabilities)
            {
                tools.Add(
                    new ProviderTool
                    {
                        Type = "function",

                        Function =
                            new ProviderToolFunction
                            {
                                Name =
                                    capability.Name,

                                Description =
                                    capability.Description,

                                Parameters =
                                    _exporter.Export(
                                        capability)
                            }
                    });
            }


            return tools;
        }
    }
}
