package com.ms.api.dto.dsorder;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class ResultDTO {
    public final static String SUCCESS = "success";
    public final static String FAIL = "fail";

    private String result;
    private String reason;
    private String code;
    private String message;

    private Map<String, Object> data = new HashMap<>();

    public boolean isSuccess() {
        return "success".equals(result);
    }

    public static ResultDTO success() {
        ResultDTO result = new ResultDTO();
        result.setResult(SUCCESS);
        result.setReason("成功");
        result.setCode(SUCCESS);
        result.setMessage("成功");
        return result;
    }

    public static ResultDTO success(Map<String, Object> data) {
        ResultDTO result = new ResultDTO();
        result.setResult(SUCCESS);
        result.setReason("成功");
        result.setCode(SUCCESS);
        result.setMessage("成功");
        result.setData(data);
        return result;
    }

    public static ResultDTO fail() {
        ResultDTO result = new ResultDTO();
        result.setResult(FAIL);
        result.setReason("失败");
        result.setCode(FAIL);
        result.setMessage("失败");
        return result;
    }

    public static ResultDTO fail(String message) {
        ResultDTO result = new ResultDTO();
        result.setResult(FAIL);
        result.setReason(message);
        result.setCode(FAIL);
        result.setMessage(message);
        return result;
    }

    public static ResultDTO fail(String code, String message) {
        ResultDTO result = new ResultDTO();
        result.setResult(FAIL);
        result.setReason(message);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
}
