package com.samsung.sample.approval.internal.interceptor;

import com.samsung.approval.annotation.ApprovalDocumentType;
import com.samsung.approval.entity.Approval;
import com.samsung.approval.entity.ApprovalStep;
import com.samsung.approval.enums.ApprovalDocStatus;
import com.samsung.approval.interceptor.ApprovalInterceptor;
import com.samsung.sample.approval.internal.InternalApprovalSampleService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

@Log4j2
@ApprovalDocumentType(names = {"internalSample"})
public class InternalApprovalSampleInterceptor implements ApprovalInterceptor {

    @Autowired
    InternalApprovalSampleService internalApprovalSampleService;
    @Override
    public void afterSubmit(Approval approval, List<ApprovalStep> approvalStepList, Map<String, Object> attribute) {
        log.debug("execute ApprovalSampleInterceptor afterSubmit");
        //상신 후 문서 상태 업데이트
        internalApprovalSampleService.updateSampleApprovalDocument(approval.getDbDocId(), ApprovalDocStatus.INPROCESS);
    }

    /**
     * 내부결재 상신취소 sampleApprovalDocument 문서 상태 업데이트.
     * @param approval 결재 정보
     * @return
     */
    @Override
    public void afterInternalApprovalCancel(Approval approval) {
    	internalApprovalSampleService.updateSampleApprovalDocument(approval.getDbDocId(), ApprovalDocStatus.CANCELLED);
    }
    
    /**
     * 내부결재 반려 sampleApprovalDocument 문서 상태 업데이트.
     * @param approval 결재 정보
     * @return
     */
    @Override
    public void afterInternalApprovalReject(Approval approval) {
    	internalApprovalSampleService.updateSampleApprovalDocument(approval.getDbDocId(), ApprovalDocStatus.REJECTED);
    }
    
    /**
     * 내부결재 완료 sampleApprovalDocument 문서 상태 업데이트.
     * @param approval 결재 정보
     * @return
     */
    @Override
    public void afterInternalApprovalCompleted(Approval approval) {
    	internalApprovalSampleService.updateSampleApprovalDocument(approval.getDbDocId(), ApprovalDocStatus.COMPLETED);
    }
}