package com.tsi.common.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.tsi.common.utils.StringUtils;
import lombok.*;

import java.io.Serializable;

/**
 * 프로세스 상태 DTO Class
 */
@Data
@Builder
public class ProcessStateDto implements Serializable {
    private static final long serialVersionUID = 1L;

//    @ApiModelProperty("프로세스 ID")  // N VARCHAR2(5)
    @JsonProperty("processId")
    private String processId;

//    @ApiModelProperty("등록시각")  // N DATE(0)
    @JsonProperty("regDate")
    private String regDate;

//    @ApiModelProperty("동작상태(0:정상, 1:종료, 2:오류발생)")  // Y VARCHAR2(1)
    @JsonProperty("runState")
    private String runState;

//    @ApiModelProperty("수신건수")  // Y NUMBER(7)
    @JsonProperty("rcvCnt")
    private Integer rcvCnt;

//    @ApiModelProperty("송신건수")  // Y NUMBER(7)
    @JsonProperty("sndCnt")
    private Integer sndCnt;

//    @ApiModelProperty("기타건수")  // Y NUMBER(7)
    @JsonProperty("etcCnt")
    private Integer etcCnt;

//    @ApiModelProperty("오류설명")  // Y VARCHAR2(255)
    @JsonProperty("errDesc")
    private String errDesc;

//    @ApiModelProperty("오류발생시간gap(regdate와 현재시간차이)")  // Y NUMBER(7)
    @JsonProperty("errTimeGap")
    private Integer errTimeGap;

    public void init() {
        this.runState = RUN_STATE.NORMAL.getValue();
        this.errDesc = "";
        this.rcvCnt = 0;
        this.sndCnt = 0;
        this.etcCnt = 0;
    }
    public void setError(String errDesc) {
        this.runState = RUN_STATE.ERROR.getValue();
        this.errDesc = StringUtils.safeSubstring(errDesc, 200);
    }

    @Getter
    public enum RUN_STATE {
        NORMAL("0"),
        STOP("1"),
        ERROR("2");

        private final String value;

        RUN_STATE(String value) {
            this.value = value;
        }

    }
}
