package cokr.xit.ens.modules.common.monitor;

import cokr.xit.ens.core.exception.code.EnsErrCd;
import cokr.xit.ens.core.monitor.Message;
import cokr.xit.ens.modules.common.code.PostSeCd;
import cokr.xit.ens.modules.common.code.StatCd;
import lombok.Builder;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Builder
public class MessageByPhase implements Message {
    private final String oClass;
    private final PostSeCd postSeCd;
    private final StatCd statCd;
    private EnsErrCd errCd;
    private String message;


    @Override
    public String create() {
        StringBuffer sb = new StringBuffer();
        sb.append("###############################################################")
                .append(System.getProperty("line.separator"))
                .append(String.format("####### ENS proccess error Info... [ -Dspring.profiles.active=%s ] #######", System.getProperty("ens.active.profile")))
                .append(System.getProperty("line.separator"))
                .append("###############################################################")
                .append(System.getProperty("line.separator"))
                .append(String.format("%s - %s(%s)", postSeCd.getCodeNm(), statCd.getCodeNm(), statCd.getCode()))
                .append(System.getProperty("line.separator"))
                .append("-------------------------------------------------------------------------------")
                .append(System.getProperty("line.separator"))
                .append("[Occurrence class]: " + oClass)
                .append(System.getProperty("line.separator"))
                .append("[Occurrence time]: ")
                .append(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")))
                .append(System.getProperty("line.separator"))
                .append("[ErrorCode]: ")
                .append(errCd.getCode())
                .append(System.getProperty("line.separator"))
                .append("[ErrorMessage]: ")
                .append(errCd.getCodeNm())
                .append(System.getProperty("line.separator"))
                .append("[Details]: ")
                .append(System.getProperty("line.separator"))
                .append(message);

        return sb.toString();
    }
}
