package com.zhongshu.card.server.core.init;

import com.zhongshu.card.client.service.org.OrganizationService;
import com.zhongshu.card.server.core.service.openAPI.OpenAPIRegisterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * 注册平台的 openAPI到openAPI网关
 *
 * @author TRX
 * @date 2024/6/3
 */
@Component
@Slf4j
public class OpenApiInit implements CommandLineRunner {

    @Autowired
    OpenAPIRegisterService openAPIRegisterService;

    @Value("${openapi.initRegister}")
    public boolean initRegister = false;

    @Override
    public void run(String... args) throws Exception {
        CompletableFuture.runAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(30);
                log.info("initRegister {}", initRegister);
                if (initRegister) {
                    openAPIRegisterService.initRegisterPAIS();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}
