package com.storlead.api;

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.sales.mail.mapper")
@Slf4j
public class StorleadMailServiceApplication {

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

    @Bean
    public ApplicationRunner startupEndpointLogger(Environment env) {
        return args -> {
            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("==================================================");
        };
    }
}
