package <%= packageName %>.config;
<%
    const builtInServicesInfo = [];
 %>
<%_
    if (applicationTypeMonolith || applicationTypeMicroservice && builtInServices && builtInServices.includes('oss')) {
        builtInServicesInfo.push('OssConfigService ossConfigService');
_%>
import <%= packageName %>.oss.service.OssConfigService;
<%_ } _%>
<%_
    if (applicationTypeMonolith || applicationTypeMicroservice && builtInServices && builtInServices.includes('idm')) {
        builtInServicesInfo.push('SmsSupplierService smsSupplierService');
_%>
import <%= packageName %>.system.service.SmsSupplierService;
<%_ } _%>
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonApplicationListener implements ApplicationListener<ApplicationReadyEvent> {
    <%_ if (applicationTypeMonolith || applicationTypeMicroservice && builtInServices && builtInServices.includes('idm')) { _%>

    private final SmsSupplierService smsSupplierService;
    <%_ } _%>
    <%_ if (applicationTypeMonolith || applicationTypeMicroservice && builtInServices && builtInServices.includes('oss')) { _%>

    private final OssConfigService ossConfigService;
    <%_ } _%>

    public CommonApplicationListener(<%- builtInServicesInfo.length ? builtInServicesInfo.join(',') : ''%>) {
    <%_ if (applicationTypeMonolith || applicationTypeMicroservice && builtInServices && builtInServices.includes('idm')) { _%>
        this.smsSupplierService = smsSupplierService;
    <%_ } _%>
    <%_ if (applicationTypeMonolith || applicationTypeMicroservice && builtInServices && builtInServices.includes('oss')) { _%>
        this.ossConfigService = ossConfigService;
    <%_ } _%>
    }

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
    <%_ if (applicationTypeMonolith || applicationTypeMicroservice && builtInServices && builtInServices.includes('oss')) { _%>
        ossConfigService.initPlatforms();
    <%_ } _%>
    <%_ if (applicationTypeMonolith || applicationTypeMicroservice && builtInServices && builtInServices.includes('idm')) { _%>
        smsSupplierService.initService();
    <%_ } _%>
    }

}
