using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Fest.WebApi
{
    public class SwaggerXClientIdHeaderParameterOperationFilter : IOperationFilter
    {
        public void Apply(OpenApiOperation operation, OperationFilterContext context)
        {
            operation.Parameters ??= new List<OpenApiParameter>();

            if (operation.Parameters.All(p => p.Name != Consts.XClientIdHeader))
                operation.Parameters.Add(new OpenApiParameter
                {
                    Name = Consts.XClientIdHeader,
                    In = ParameterLocation.Header,
                    Required = false,
                    Schema = new OpenApiSchema
                    {
                        Type = "Guid"
                    }
                });
        }
    }
}
