package cokr.xit.ens.modules.ktsigntalk.direct.service.event;

import cokr.xit.ens.modules.ktsigntalk.direct.service.support.KtSigntalkRsltFetcher;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Slf4j
@Component
@RequiredArgsConstructor
public class KtSigntalkSentEventListener {
    private final KtSigntalkRsltFetcher ktSigntalkRsltFetcher;


    @Async
    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
    public void ktSigntalkSent(KtSigntalkSentEvent event) {

        StringBuffer sb = new StringBuffer();
        sb.append("=======================================================")
                .append("[ENS] KT 인증톡 전송 후 상태갱신")
                .append("요청ID: " + event.getSendMastId())
                .append("상태갱신 결과: " + ktSigntalkRsltFetcher.execute(event.getSendMastId()).toString())
                .append("=======================================================");
        log.info(sb.toString());
    }
}
