package com.ssm.core.bean;


import com.fasterxml.jackson.annotation.JsonInclude;
import com.ssm.manage.entity.SmsException;
import com.ssm.manage.response.ResponseCode;

import java.io.Serializable;
import java.util.Collection;
import java.util.Map;


@SuppressWarnings("rawtypes")
@JsonInclude(JsonInclude.Include.NON_NULL)
public  class GenericResponse<T> implements Serializable {
	
	
	/**
	 * Serial version UID for the class to uniquely identify the object during serialization process
	 */
	public static final long serialVersionUID = 1L;
	
	/**
	 * An array that contains the actual objects
	 */
	private Collection<T> rows;
	
	/**
	 * An Map that contains the actual objects
	 */
	private Map mapData;
	
	/**
	 * A String containing response code.
	 */
	private String code;
	
	/**
	 * An int that contains the count of all records
	 */
	private Integer count;
	
	/**
	 * A String containing message.
	 */
	private String message;

	private T data;


	public Collection<T> getRows() {
		return rows;
	}

	public void setRows(Collection<T> rows) {
		this.rows = rows;
	}

	public Map getMapData() {
		return mapData;
	}

	public void setMapData(Map mapData) {
		this.mapData = mapData;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public GenericResponse() {
	}

	public GenericResponse(Collection<T> rows, String code, int count, String message, Map mapData) {
		this.rows = rows;
		this.code = code;
		this.count = count;
		this.message = message;
		this.mapData = mapData;
	}

	public GenericResponse(Collection<T> rows, String code, int count, String message) {
		this.rows = rows;
		this.code = code;
		this.count = count;
		this.message = message;
	}

	public GenericResponse(Map mapData, String code, int count, String message) {
		this.mapData = mapData;
		this.code = code;
		this.count = count;
		this.message = message;
	}

	public GenericResponse(ResponseCode code){
		this.code = code.getCode();
		this.message = code.getMsg();
	}

	public GenericResponse(ResponseCode code,String msg){
		this.code = code.getCode();
		this.message = String.format(code.getMsg(), msg);
	}

	public void setCodeAndMsg(ResponseCode code){
		this.code = code.getCode();
		this.message = code.getMsg();
	}

	public void setCodeAndMsg(ResponseCode code,String msg){
		this.code = code.getCode();
		this.message = String.format(code.getMsg(), msg);
	}

	public void setCodeAndMsg(SmsException e){
		this.code = e.getCode();
		this.message = e.getMessage();
	}


}
