package com.gic.haoban.manage.web.handle;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.enterprise.api.dto.security.DownloadReportDTO;
import com.gic.haoban.manage.web.utils.data.StoreAuthUtils;
import com.gic.haoban.manage.web.vo.eventtracking.WechatEventTrackingStoreGroupVO;
import com.gic.web.common.download.DownloadHandlerAbstract;
import com.gic.web.common.download.context.Context;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * 数据-登录数据-好办使用详情
 */
@Component
public class WechatEventTrackingStoreGroupHandle extends DownloadHandlerAbstract<WechatEventTrackingStoreGroupVO> {

    @Autowired
    private StoreAuthUtils storeAuthUtils;

    @Override
    public List<WechatEventTrackingStoreGroupVO> getData(Context context, String searchDataParams, Integer currentPage) {
        List<JSONObject> list = storeAuthUtils.getDataCommon(searchDataParams, currentPage,
                "数据-登录数据-好办使用详情导出日志进来", getPageSize(), false).getRows();
        list = storeAuthUtils.deleteTotalData(list);
        if (CollectionUtils.isNotEmpty(list)) {
            List<WechatEventTrackingStoreGroupVO> result = JSONObject.parseArray(JSON.toJSONString(list), WechatEventTrackingStoreGroupVO.class);
            return result;
        }
        return Collections.EMPTY_LIST;
    }

    @Override
    public List<String> getColumnNames() {
        return Collections.EMPTY_LIST;
    }

    @Override
    public List<String> getColumnNames(Context context){
        DownloadReportDTO downloadReportDTO = context.getDownloadReportDTO();
        String searchDataParams = downloadReportDTO.getSearchDataParams();
        JSONObject jsonObject = JSONObject.parseObject(searchDataParams);
        List<String> list = (List<String>) jsonObject.get("indexList");
        return list;
    }

    @Override
    public LinkedHashMap<String, List<String>> doubleColumnNames() {
        return null;
    }

    @Override
    public List<String> getColumns() {
        return Collections.EMPTY_LIST;
    }

    @Override
    public List<String> getColumns(Context context) {
        DownloadReportDTO downloadReportDTO = context.getDownloadReportDTO();
        String searchDataParams = downloadReportDTO.getSearchDataParams();
        JSONObject jsonObject = JSONObject.parseObject(searchDataParams);
        List<String> list = (List<String>) jsonObject.get("fieldList");
        return list;
    }
}
