using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Pos.Api.Database;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Pos.Api.Helper
{
    public class ApiKeyHeaderOperationFilter : IOperationFilter
    {
        private readonly IConfiguration _config;

        public ApiKeyHeaderOperationFilter(IConfiguration config)
        {
            _config = config;
        }

        public void Apply(OpenApiOperation operation, OperationFilterContext context)
        {
            string? apiKey = _config["ApiKey"];
            operation.Parameters.Add(new OpenApiParameter
            {
                Name = "ApiKey",
                In = ParameterLocation.Header,
                Required = true,
                Schema = new OpenApiSchema
                {
                    Type = "string",
                    Default = new OpenApiString(apiKey)
                }
            });
        }
    }
}
