package com.zksy.common.utils.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * @Author sy
 * @Date 2022/04/11
 * @Description
 */
@Data
@ApiModel
public class Response<T> extends ResponseBase implements Serializable {
    @ApiModelProperty(name = "data", value = "data数据", position = 4)
    private T data;

    public Response() {

    }

    public Response(ResponseCode responseCode) {
        super(responseCode);
    }

    public Response(ResponseCode responseCode, String error) {
        super(responseCode, error);
    }

    public Response(Integer code, String message) {
        super(code, message);
    }

    public Response(Integer code, String message, String error) {
        super(code, message, error);
    }

    public Response(ResponseCode responseCode, T data) {
        super(responseCode);
        this.data = data;
    }

    public Response(Integer code, String message, T data) {
        super(code, message);
        this.data = data;
    }

    public static Response<String> success() {
        return new Response<>(ResponseCode.SUCCESS);
    }

    public static <T> Response<T> success(T data) {
        return new Response<>(ResponseCode.SUCCESS, data);
    }

    public static <T> Response<T> success(String msg, T data) {
        return new Response<>(ResponseCode.SUCCESS.code, msg, data);
    }

    public static <T> Response<T> error(ResponseCode responseCode) {
        return new Response<>(responseCode);
    }

    public static <T> Response<T> error(ResponseCode responseCode, String error) {
        return new Response<>(responseCode, error);
    }

    public static <T> Response<T> error(String error) {
        return new Response<>(ResponseCode.ERROR_500.code, error);
    }

    public static <T> Response<T> error(Integer code, String message) {
        return new Response<>(code, message);
    }

    public static <T> Response<T> error(Integer code, String message, String error) {
        return new Response<>(code, message, error);
    }

    public static <T> Response<T> fail(ResponseCode responseCode) {
        return new Response<>(responseCode);
    }

    public static <T> Response<T> fail(ResponseCode responseCode, String error) {
        return new Response<>(responseCode, error);
    }

    public static <T> Response<T> fail(String error) {
        return new Response<>(ResponseCode.FAILED.code, error);
    }

    public static <T> Response<T> fail(String error, T data) {
        return new Response<>(ResponseCode.FAILED.code, error, data);
    }

    public static <T> Response<T> fail(Integer code, String message) {
        return new Response<>(code, message);
    }

    public static <T> Response<T> fail(Integer code, String message, String error) {
        return new Response<>(code, message, error);
    }

    public static <T> Response<T> paramError(String message) {
        return new Response<>(ResponseCode.ParamError.code, message);
    }

    public static <T> Response<T> noPermission() {
        return new Response<>(ResponseCode.ERROR_403);
    }
}
