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

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.stereotype.Component;

import java.net.InetAddress;

/**
 * 启动时打印 Swagger 文档地址
 */
@Slf4j
@Component
public class SwaggerDocPrinter implements ApplicationRunner {

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

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

    @Override
    public void run(ApplicationArguments args) throws Exception {
        String ip = InetAddress.getLocalHost().getHostAddress();
        String ctx = contextPath == null ? "" : contextPath;
        
        String line = "=".repeat(60);
        
        log.info("\n" + line +
                "\n  应用启动成功！Swagger 文档地址：" +
                "\n" + line +
                "\n  本地访问:    http://localhost:" + port + ctx + "/doc.html" +
                "\n  网络访问:    http://" + ip + ":" + port + ctx + "/doc.html" +
                "\n" + line +
                "\n  API 文档资源:" +
                "\n  - Knife4j UI:        http://localhost:" + port + ctx + "/doc.html" +
                "\n  - Swagger Resources: http://localhost:" + port + ctx + "/swagger-resources" +
                "\n" + line);
    }
}
