package com.xingxi.api.common;

import lombok.Getter;
import lombok.Setter;

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

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

    public ResponseDTO(){}

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

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

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