package com.writeoff.common.api;

import com.writeoff.common.web.RequestIdContext;
import java.time.Instant;

public class ApiResponse<T> {
    private int code;
    private String message;
    private T data;
    private String requestId;
    private String timestamp;

    public ApiResponse(int code, String message, T data, String requestId, String timestamp) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.requestId = requestId;
        this.timestamp = timestamp;
    }

    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>(0, "success", data, RequestIdContext.get(), Instant.now().toString());
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    public String getRequestId() {
        return requestId;
    }

    public String getTimestamp() {
        return timestamp;
    }
}
