package kz.konturai.parser.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI api() {
        final String securitySchemeName = "bearerAuth";

        return new OpenAPI()
                .servers(List.of(new Server().url("http://localhost:8080")))
                .info(new Info()
                        .title("Marketing Parser API")
                        .description("""
                                RSS ingestion, AI-driven marketing analysis and strategy generation, \
                                report rendering (PDF/DOCX/Markdown), social media publishing and \
                                Facebook lead collection for the KonturAI platform.""")
                        .version("1.0.0"))
                // 1. Добавляем возможность ввода токена (кнопка Authorize)
                .addSecurityItem(new SecurityRequirement().addList(securitySchemeName))
                // 2. Описываем схему безопасности (тип, формат токена)
                .components(new Components()
                        .addSecuritySchemes(securitySchemeName,
                                new SecurityScheme()
                                        .name(securitySchemeName)
                                        .type(SecurityScheme.Type.HTTP)
                                        .scheme("bearer")
                                        .bearerFormat("JWT")
                        ));
    }
}