package com.game.common.core.domain;

import com.game.common.core.page.TableDataInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@ApiModel(value = "HttpRetPageArr", description = "HttpRetPageArr")
@Data
public class HttpRetPageArr<T> implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	@ApiModelProperty(value = "44001=网络错误或服务器返回异常；44002=json解析或转model异常；44003=token失效了；44006=系统关闭中;", name = "code")
	public int code;

	@ApiModelProperty(value = "返回的消息", name = "msg")
	public String msg;

	/*
	 * 每页查询多少条
	 */
	@ApiModelProperty(value = "每页条数", name = "pageSize")
	public int pageSize;

	/*
	 * 查询第几页
	 */
	@ApiModelProperty(value = "当前页数", name = "pageIndex")
	public int pageIndex;

	/*
	 * 返回数据，总共有多少页
	 */
	@ApiModelProperty(value = "总页数", name = "outTotalPage")
	public int outTotalPage;

	/*
	 * 返回数据，总共有多少条记录
	 */
	@ApiModelProperty(value = "总条数", name = "outTotalCount")
	public int outTotalCount;

	@ApiModelProperty(value = "返回实体列表", name = "retArr")
	public List<T> retArr;

	//为了ApiCacheRet 接口保留的
	public String retStr;

	
	public void setPageInfo(int pageSize, int pageIndex, int outTotalPage, int outTotalCount) {
		this.pageSize = pageSize;
		this.pageIndex = pageIndex;
		this.outTotalPage = outTotalPage;
		this.outTotalCount = outTotalCount;

	}

	public HttpRetPageArr(int code, String msg, List<T> retObj) {
		this.code = code;
		this.msg = msg;
		this.retArr = retObj;
	}

	public static <T> HttpRetPageArr<T> genResult(int code, String msg, List<T> retObj) {
		HttpRetPageArr<T> result = new HttpRetPageArr<T>(code, msg, retObj);
		return result;
	}



	public static <T> HttpRetPageArr<T> genResultPage(int code, String msg, TableDataInfo<T> tableDataInfo) {
		HttpRetPageArr<T> result = new HttpRetPageArr<T>(code, msg, tableDataInfo.getRows());
		result.outTotalCount = Integer.parseInt(String.valueOf(tableDataInfo.getTotal()));
		return result;
	}

	public static <T> HttpRetPageArr<T> success(String msg, List<T> data) {
		return genResult(1, msg, data);
	}

	public static <T> HttpRetPageArr<T> success(String msg, TableDataInfo<T> tableDataInfo) {
		return genResultPage(1, msg, tableDataInfo);
	}

	public static <T> HttpRetPageArr<T> success(String msg) {
		return genResult(1, msg, null);
	}

	public static <T> HttpRetPageArr<T> fail(String message) {
		return genResult(2, message, null);
	}

	public static <T> HttpRetPageArr<T> fail(int code, String message) {
		return genResult(code, message, null);
	}

	@Override
	public String toString() {
		return "HttpRetArr{" + "code=" + code + ", msg='" + msg + '\'' + ", retArr=" + retArr + '}';
	}

}
