package com.energy.manage.common.reponse;

import java.util.Optional;

/**
 * 请求响应实体
 */
public class HttpResult {

    private boolean success;
    private int statusCode;
    private String message;
    private String data;

    private HttpResult(boolean success, int statusCode, String message, String data) {
        this.success = success;
        this.statusCode = statusCode;
        this.message = message;
        this.data = data;
    }

    public static HttpResult success(int statusCode, String data) {
        return new HttpResult(true, statusCode, "请求成功", data);
    }

    public static HttpResult fail(String message) {
        return new HttpResult(false, -1, message, null);
    }

    public static HttpResult fail(int statusCode, String message) {
        return new HttpResult(false, statusCode, message, null);
    }

    // Getter方法
    public boolean isSuccess() {
        return success;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public String getMessage() {
        return message;
    }

    public Optional<String> getData() {
        return Optional.ofNullable(data);
    }
}
