using Knoks.Api.Entities;
using Knoks.Core;
using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;
using System;
using System.Collections.Generic;
using System.Reflection;

namespace Knoks.Api.Specification
{
    class ApiSwaggerSchemaFilter : ISchemaFilter
    {
        public void Apply(Schema model, SchemaFilterContext context)
        {
            //model.Discriminator = "kuku description";

            //if (context.SystemType.GetTypeInfo().IsGenericType && context.SystemType.GetGenericTypeDefinition() == typeof(ApiResponse<>))
            //{
            //    var genericType = context.SystemType.GenericTypeArguments[0];
            //    if (genericType.GetTypeInfo().IsGenericType && genericType.GetGenericTypeDefinition() == typeof(Dictionary<,>))
            //    {
            //        var keyType = genericType.GenericTypeArguments[0];
            //        var valueType = genericType.GenericTypeArguments[1];
            //        var add = genericType.GetMethod("Add", new[] { keyType, valueType });

            //        var keyObj = Activator.CreateInstance(keyType);
            //        var valueObj = "";//Activator.CreateInstance("");

            //        var dic = Activator.CreateInstance(genericType);
            //        add.Invoke(dic, new object[] { keyObj, valueObj });

            //        model.Title = genericType.Name;
            //        model.Example = dic;
            //    }
            //}
        }
    }
}

