package com.kmall.manager.entity.pay.data.open;

import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * @author Scott Chen
 * @since 1.0
 * 2018-12-21
 */
public class ResponseMsg implements Serializable {

    private static final long serialVersionUID = 6556920017380881713L;

    public static final String SUCCESS_CODE = "10000";
    public static final String ERROR_CODE = "20000";

    private String code;
    private String message;
    private int total;
    private Long serviceTime;

    public ResponseMsg(){}

    public ResponseMsg(String code, String message, Long serviceTime) {
        this.code = code;
        this.message = message;
        this.serviceTime = serviceTime;
    }

    public static Builder builder() {
        return new Builder();
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public Long getServiceTime() {
        return serviceTime;
    }

    public void setServiceTime(Long serviceTime) {
        this.serviceTime = serviceTime;
    }


    /**
     * 消息构建器类
     */
    public static class Builder {
        private String code;
        private String message;
        private int total;
        private Long serviceTime;

        public Builder() {
            this.code = SUCCESS_CODE;
            this.message = "";
            this.total = 0;
            this.serviceTime = System.currentTimeMillis();
        }


        public Builder(String code, String message, int total){
            this.code = StringUtils.isBlank(code) ? SUCCESS_CODE : code;
            this.message = code.equals(SUCCESS_CODE) ? "" : message;
            this.total = total;
            this.serviceTime = System.currentTimeMillis();
        }


        public Builder setCode(String code) {
            this.code = code;
            return this;
        }

        public Builder setMessage(String message) {
            this.message = message;
            return this;
        }


        public ResponseMsg build() {
            ResponseMsg message = new ResponseMsg();
            message.code = this.code;
            message.message = this.message;
            message.total = this.total;
            message.serviceTime = this.serviceTime;
            return message;
        }

    }

}
