package kr.xit.biz.ens.cmm;

import java.util.HashMap;
import java.util.Map;

import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;

import kr.xit.biz.common.ApiConstants;
import kr.xit.biz.ens.model.cmm.SndngMssageParam;
import kr.xit.core.support.utils.Checks;

/**
 * <pre>
 * description :
 *
 * packageName : kr.xit.biz.ens.cmm
 * fileName    : CmmEnsBizUtils
 * author      : limju
 * date        : 2023-10-31
 * ======================================================================
 * 변경일         변경자        변경 내용
 * ----------------------------------------------------------------------
 * 2023-10-31    limju       최초 생성
 *
 * </pre>
 */
public class CmmEnsBizUtils {

    /**
     * API 서버 호출을 위한 헤더 set
     * @return Map<String,String>
     */
    public static Map<String,String> getHeadeMap(){
        final Map<String, String> map = new HashMap<>();
        map.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
        //map.put(HttpHeaders.AUTHORIZATION, "");
        return map;
    }

    /**
     * <pre>
     * get 발송구분코드(문서중개자)
     * @param dto SndngMssageParam
     * @return SndngSeCode 발송구분코드(문서중개자)
     * </pre>
     */
    public static ApiConstants.SndngSeCode getSndngSeCodFromTrySeq(final SndngMssageParam dto) {
        String[] tryVal = {
            Checks.checkVal(dto.getTry1(), ""),
            Checks.checkVal(dto.getTry2(), ""),
            Checks.checkVal(dto.getTry3(), "")
        };
        String seCode = tryVal[dto.getTrySeq() - 1];

        return ApiConstants.SndngSeCode.getSndngSeCode(seCode);
    }

    /**
     * 춘천 또는 천안 전자결재 발송 진행상태 set
     * @param dto SndngMssageParam
     * @param processStatus 발송처리상태
     */
    public static void setMappingProcessStatus(final SndngMssageParam dto, final String processStatus) {
        if(ApiConstants.IS_CCN)     dto.setNewSndngProcessSttus(ApiConstants.MappingCcnSndngProcessStatus.fromEns(processStatus));
        else                        dto.setNewSndngProcessSttus(ApiConstants.MappingCanSndngProcessStatus.fromEns(processStatus));
    }
}
