package cokr.xit.ens.core.eventlistner._ignore;

import cokr.xit.ens.core.eventlistner._ignore.events.AcceptAfterTransactionEvent;
import cokr.xit.ens.core.eventlistner._ignore.events.AcceptBeforeTransactionEvent;
import cokr.xit.ens.core.eventlistner._ignore.events.AcceptEvent;
import cokr.xit.ens.modules.kkomydoc.service.support.KkoMydocAcceptor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Slf4j
@Component
@RequiredArgsConstructor
public class AcceptEventListener {
    private final KkoMydocAcceptor acceptor;

//    @Override
//    public void process(Event e) {
//
//    }

    @EventListener
    @Order(1)
    public void process1(final AcceptEvent event){
        log.info("AcceptEventHandler Process 1 호출......");
    }
    @EventListener
    @Order(2)
    public void process2(final AcceptEvent event){
        log.info("AcceptEventHandler Process 2 호출......");
    }
    
    @TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
    public void beforeTransactionProcess(AcceptBeforeTransactionEvent event){
        log.info("AcceptEventHandler beforeTransactionProcess 호출......");
        event.callback();
    }
    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
    public void afterTransactionProcess(AcceptAfterTransactionEvent event){
        log.info("AcceptEventHandler afterTransactionProcess 호출......");
        event.callback();
    }
    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMPLETION)
    public void completedTransactionProcess(AcceptAfterTransactionEvent event){
        log.info("AcceptEventHandler completedTransactionProcess 호출......");
        event.completed();
    }
}
