package com.schisandra.auth.common.entity;

import lombok.Data;

@Data
public class CaptchaResult<T> {

    private Integer code;

    private String msg;

    private Boolean success;

    private T data;

    public static CaptchaResult ok() {
        CaptchaResult result = new CaptchaResult();

        result.setCode(0);
        result.setSuccess(true);
        result.setMsg("Success");
        return result;
    }

    public static <T> CaptchaResult ok(T data) {
        CaptchaResult result = new CaptchaResult();
        result.setSuccess(true);
        result.setCode(0);
        result.setMsg("Success");
        result.setData(data);
        return result;
    }

    public static CaptchaResult fail() {
        CaptchaResult result = new CaptchaResult();
        result.setSuccess(false);
        result.setCode(1);
        result.setMsg("验证失败");
        return result;
    }

    public static CaptchaResult failWithSuccess() {
        CaptchaResult result = new CaptchaResult();
        result.setSuccess(true);
        result.setCode(1);
        result.setMsg("验证失败");
        return result;
    }

    // 登录验证特殊情况
    public static CaptchaResult failWithCode() {
        CaptchaResult result = new CaptchaResult();
        result.setSuccess(false);
        result.setCode(0);
        result.setMsg("验证成功");
        return result;
    }

    public static <T> CaptchaResult failWithCode(T data) {
        CaptchaResult result = new CaptchaResult();
        result.setSuccess(false);
        result.setCode(0);
        result.setData(data);
        result.setMsg("验证成功");
        return result;
    }

    public static <T> CaptchaResult fail(T data) {
        CaptchaResult result = new CaptchaResult();
        result.setSuccess(false);
        result.setCode(1);
        result.setMsg("验证失败");
        result.setData(data);
        return result;
    }
}
