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.chat.GroupChatClerkVO;
import com.gic.haoban.manage.web.vo.chat.SingleChatClerkVO;
import com.gic.haoban.manage.web.vo.wechatwork.WechatWorkLostStoreGroupVO;
import com.gic.web.common.download.DownloadHandlerAbstract;
import com.gic.web.common.download.context.Context;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

/**
 * @author shangfeng
 * @date 2024-06-21 11:33:54
 */
@Component
public class SingleChatClerkDataHandle  extends DownloadHandlerAbstract<SingleChatClerkVO> {

    private static final Logger LOGGER = LogManager.getLogger(WechatWorkLostStoreGroupHandle.class);

    @Autowired
    private StoreAuthUtils storeAuthUtils;

    @Override
    public List<SingleChatClerkVO> getData(Context context, String searchDataParams, Integer currentPage) {
        List<JSONObject> list = storeAuthUtils.getDataCommon(searchDataParams, currentPage,
                "好办单聊统计-导购维度-导出日志", getPageSize(), false).getRows();
        if (CollectionUtils.isNotEmpty(list)) {
            List<SingleChatClerkVO> result = JSONObject.parseArray(JSON.toJSONString(list), SingleChatClerkVO.class);
            return result;
        }
        return Lists.newArrayList();
    }

    @Override
    public List<String> getColumnNames() {
        return Lists.newArrayList();
    }

    @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 Lists.newArrayList();
    }

    @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;
    }
}
