package com.lideeyunji.tool.framework.yunji.model;

import com.lideeyunji.tool.framework.yunji.utils.FuncBase;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class ResultDataModel {
    private boolean exitFlag=false;//是否退出
    private Long total;
    private List<Map<String,Object>> records;//列表



    public Long getTotal() {
        return total;
    }

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

    public List<Map<String, Object>> getRecords() {
        return records;
    }

    public void setRecords(List<Map<String, Object>> records) {
        this.records = records;
    }

    public boolean isExitFlag() {
        return exitFlag;
    }

    public void setExitFlag(boolean exitFlag) {
        this.exitFlag = exitFlag;
    }


    public ResultDataModel(){
        this.total=0L;
        this.setRecords(new ArrayList<>());
    }

    /**
     * 取一条
     * @param list
     * @return
     */
    public static ResultDataModel fomatOne(List<Map<String, Object>> list){
        if(FuncBase.isEmpty(list)){
            ResultDataModel resultDataModel = new ResultDataModel();
            resultDataModel.setTotal(0L);
            resultDataModel.setRecords(new ArrayList<>());
            return resultDataModel;
        }
        Map<String, Object> tmpMap = list.get(0);
        list.clear();
        list.add(tmpMap);
        ResultDataModel model=new ResultDataModel();
        model.setTotal(FuncBase.toLong(list.size()));
        model.setRecords(list);
        return model;
    }

    /**
     * 只处理数据，不改变总数的情况下
     * @param list
     * @return
     */
    public static ResultDataModel fomatList(List<Map<String, Object>> list){
        if(FuncBase.isEmpty(list)){
            ResultDataModel resultDataModel = new ResultDataModel();
            resultDataModel.setTotal(0L);
            resultDataModel.setRecords(new ArrayList<>());
            return resultDataModel;
        }
        ResultDataModel model=new ResultDataModel();
        model.setRecords(list);
        return model;
    }

    /**
     * 只处理数据，不改变总数的情况下
     * @param dataMap
     * @return
     */
    public static ResultDataModel fomatMap(Map<String, Object> dataMap){
        List<Map<String, Object>> list = Collections.singletonList(dataMap);
        ResultDataModel model=new ResultDataModel();
        model.setRecords(list);
        return model;
    }

    /**
     * 处理数据和改变总数的情况下
     * @param total
     * @param list
     * @return
     */
    public static ResultDataModel fomat(long total,List<Map<String, Object>> list){
        ResultDataModel model=new ResultDataModel();
        model.setTotal(total);
        model.setRecords(list);
        return model;
    }


}
