package com.shkj.wcs.third.rcs.vo;

import lombok.Data;

import java.util.Collections;
import java.util.List;

@Data
public class RcsResponseVo<T> {
    private String  code;
    private String message;
    private List<T> data;


    // 成功
    public static <T> RcsResponseVo<T> success(List<T> data) {
        RcsResponseVo<T> response = new RcsResponseVo<>();
        response.setCode("SUCCESS");
        response.setMessage("成功");
        response.setData(data != null ? data : Collections.emptyList());
        return response;
    }

    // 无数据的成功响应
    public static <T> RcsResponseVo<T> success() {
        return success(null);
    }

    // 单对象成功响应（非List场景）
    public static <T> RcsResponseVo<T> success(T item) {
        RcsResponseVo<T> response = new RcsResponseVo<>();
        response.setCode("SUCCESS");
        response.setMessage("成功");
        response.setData(item != null ?
                Collections.singletonList(item) :
                Collections.emptyList());
        return response;
    }



    // 错误响应
    public static <T> RcsResponseVo<T> error(String msg) {
        RcsResponseVo<T> response = new RcsResponseVo<>();
        response.setCode("ERROR");
        response.setMessage(msg);
        response.setData(Collections.emptyList());
        return response;
    }

}