package com.qryord.mp.common;

import java.io.Serializable;
import java.time.LocalDateTime;

public class RespResultModel<T> implements Serializable {
    private int code = 200;
    private LocalDateTime timestamp;
    private boolean success;
    private String message = "successful";
    private String requestId;
    private T data;

    public RespResultModel(){}

    public RespResultModel(T data){
        this.success = true;
        this.timestamp = LocalDateTime.now();
        this.data = data;
    }

    public RespResultModel(int code){
        this.code = code;
        this.success = code == 200;
        this.timestamp = LocalDateTime.now();
    }

    public RespResultModel(String message){
        this.code = 500;
        this.success = false;
        this.message = message;
        this.timestamp = LocalDateTime.now();
    }

    public int getCode() {
        return code;
    }

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

    public LocalDateTime getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(LocalDateTime timestamp) {
        this.timestamp = timestamp;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

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

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    @Override
    public String toString() {
        return "ResponseDTO{" +
                "code=" + code +
                ", timestamp=" + timestamp +
                ", success=" + success +
                ", message='" + message + '\'' +
                ", requestId='" + requestId + '\'' +
                ", data=" + data +
                '}';
    }
}
