package com.sdtool.common.entity.base;

import com.sdtool.common.datas.HttpCode;
import com.sweetfish.source.PageFlipper;

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

@SuppressWarnings("rawtypes")
public class InvokeCallResult extends BaseEntity {

    private int httpCode;

    private String msg;

    private Date timestamp;

    private String data;

    private int pageNum;

    private int pageSize;

    private int pages;

    private long total;

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

    public InvokeCallResult() {
    }

    public InvokeCallResult(int httpCode, String msg) {
        this.httpCode = httpCode;
        this.msg = msg;
    }

    public static InvokeCallResult success() {
        return new InvokeCallResult(HttpCode.OK.value(), "");
    }

    public static InvokeCallResult error(int errCode, String errorMsg) {
        return new InvokeCallResult(errCode, errorMsg);
    }

    public InvokeCallResult page(PageFlipper pageFlipper) {
        if (pageFlipper != null) {
            this.pageNum = pageFlipper.getPageIndex();
            this.pageSize = pageFlipper.getPageSize();
            this.total = pageFlipper.getTotal();
            this.pages = pageFlipper.getPageTotal();
        } else {
            this.total = 0L;
            this.pages = 0;
        }
        return this;
    }

    public InvokeCallResult data(String data) {
        this.data = data;
        return this;
    }

    public InvokeCallResult collection(Map<String, String> collection) {
        this.collection = collection;
        return this;
    }

    public int getHttpCode() {
        return httpCode;
    }

    public void setHttpCode(int httpCode) {
        this.httpCode = httpCode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    public String getData() {
        return data;
    }

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

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public Map<String, String> getCollection() {
        return collection;
    }

    public void setCollection(Map<String, String> collection) {
        this.collection = collection;
    }
}
