package cn.meowrain.aioj.backend.question.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Swagger 配置
 */
@Configuration
@Slf4j
public class SwaggerConfiguration implements ApplicationRunner {

    @Value("${server.port:8080}")
    private String serverPort;

    @Value("${server.servlet.context-path:}")
    private String contextPath;

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("AIOJ 题目服务 API 文档")
                        .version("2.0")
                        .description("提供题目管理、测试用例管理等功能")
                        .contact(new Contact()
                                .name("AIOJ Team")
                                .email("contact@aioj.com")));
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("✨API Document: http://127.0.0.1:{}{}/doc.html", serverPort, contextPath);
    }
}
