package cn.reghao.tnb.auth.app.config.spring;

import cn.reghao.tnb.auth.app.service.AccountRegistryService;
import cn.reghao.tnb.auth.app.service.PubkeyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @author reghao
 * @date 2022-03-23 09:22:01
 */
@Slf4j
@Component
public class SpringLifecycle implements ApplicationRunner, DisposableBean {
    private final PubkeyService pubkeyService;
    private final AccountRegistryService accountRegistryService;

    public SpringLifecycle(PubkeyService pubkeyService, AccountRegistryService accountRegistryService) {
        this.pubkeyService = pubkeyService;
        this.accountRegistryService = accountRegistryService;
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        pubkeyService.getPrivateKey();
        accountRegistryService.createAdminAccount();
        log.info("AuthService 启动...");
    }

    @Override
    public void destroy() {
        log.info("AuthService 停止...");
    }
}
