package com.fuyuanshen.common.core.domain;

import lombok.Data;

/**
 * @Description: 返回体
 * @Author: WY
 * @Date: 2025/6/2
 **/
@Data
public class ResponseVO<T> {

    private Integer code; // 成功:0  失败:-1
    private String msg;
    private T data;

    public ResponseVO(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseVO(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    // 静态方法，用于创建成功的响应
    public static <T> ResponseVO<T> success() {
        return new ResponseVO<>(0, "操作成功", null);
    }

    public static <T> ResponseVO<T> success(T data) {
        return new ResponseVO<>(0, "操作成功", data);
    }

    public static <T> ResponseVO<T> success(String msg, T data) {
        return new ResponseVO<>(0, msg, data);
    }

    // 静态方法，用于创建失败的响应
    public static <T> ResponseVO<T> fail(String msg) {
        return new ResponseVO<>(-1, msg, null);
    }

    public static <T> ResponseVO<T> fail(String msg, T data) {
        return new ResponseVO<>(-1, msg, data);
    }

    // 链式方法 - 添加泛型支持
    public <R> ResponseVO<R> withData(R data) {
        return new ResponseVO<>(this.code, this.msg, data);
    }

    public ResponseVO<T> withMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public ResponseVO<T> withCode(Integer code) {
        this.code = code;
        return this;
    }
}