package org.springblade.common.upyzt.exception;

import lombok.Getter;

@Getter
public abstract class UpyztException extends Exception {

    private static final long serialVersionUID = 1L;

    private String code;

    private String issue;

    private String field;

    private int statusCode;

    private String reqId;

    public UpyztException(String message) {
        super(message, null);
    }

    public UpyztException(String message, Throwable e) {
        super(message, e);
    }

    public UpyztException(String message, String code, int statusCode) {
        super(message, null);
        this.code = code;
        this.statusCode = statusCode;
    }

    public UpyztException(String message, String code, int statusCode, Throwable e) {
        super(message, e);
        this.code = code;
        this.statusCode = statusCode;
    }


    public UpyztException(String message, String code, int statusCode, String reqId) {
        super(message, null);
        this.code = code;
        this.statusCode = statusCode;
        this.reqId = reqId;
    }

    public UpyztException(String message, String code, String field, String issue, int statusCode, String reqId) {
        super(message, null);
        this.code = code;
        this.field = field;
        this.issue = issue;
        this.statusCode = statusCode;
        this.reqId = reqId;
    }

    public UpyztException(String message, String code, String field, String issue, int statusCode, Throwable e) {
        super(message, e);
        this.code = code;
        this.field = field;
        this.issue = issue;
        this.statusCode = statusCode;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(super.toString());
        if (code != null) {
            sb.append("; code: ").append(code);
        }
        if (field != null) {
            sb.append("; field: ").append(field);
        }
        if (issue != null) {
            sb.append("; issue: ").append(issue);
        }
        if (reqId != null) {
            sb.append("; request-id: ").append(reqId);
        }

        return sb.toString();
    }
}
