using System.Text.Json.Serialization;
using Tiku.Api.OpenApi;
using Tiku.Api.Security;

namespace Tiku.Api.Configuration;

internal static class ApiPresentationExtensions
{
    internal static IServiceCollection AddApiPresentation(this IServiceCollection services)
    {
        services.AddControllers(options =>
                options.Conventions.Add(new EndpointAuthorizationMetadataConvention()))
            .AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
            });
        services.AddOpenApi(options =>
        {
            options.AddDocumentTransformer<BearerSecuritySchemeTransformer>();
            options.AddOperationTransformer<PlatformOperationMetadataTransformer>();
        });
        services.AddProblemDetails();

        return services;
    }
}