package com.storlead;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

import java.net.InetAddress;

@SpringBootApplication(scanBasePackages = "com.storlead")
@MapperScan({
        "com.storlead.trade.mapper",
        "com.storlead.user.mapper",
        "com.storlead.sms.mapper",
        "com.storlead.system.mapper",
        "com.storlead.sales.mapper",
        "com.storlead.mail.mapper",
        "com.storlead.message.mapper"
})
@Slf4j
public class StorleadTradeApplication {

    public static void main(String[] args) {
        SpringApplication.run(StorleadTradeApplication.class, args);
    }

    @Bean
    public ApplicationRunner startupEndpointLogger(Environment env) {
        return new ApplicationRunner() {
            @Override
            public void run(ApplicationArguments args) throws Exception {
                String port = env.getProperty("server.port", "8080");
                String contextPath = env.getProperty("server.servlet.context-path", "");
                String hostAddress = InetAddress.getLocalHost().getHostAddress();

                String base = "http://" + hostAddress + ":" + port + contextPath;
                log.info("==================================================");
                log.info("API Base URL: {}/", base);
                log.info("Swagger URL : {}/doc.html", base);
                log.info("Swagger URL : {}/swagger-ui.html", base);
                log.info("==================================================");
            }
        };
    }
}
