package com.liangjian.dataplatform.member.service.impl;

import com.liangjian.dataplatform.member.dao.fourthly.MemDataDictoryRepository;
import com.liangjian.dataplatform.member.dao.tertiary.DataDictoryRepository;
import com.liangjian.dataplatform.member.entity.po.fourthly.MemDataDictory;
import com.liangjian.dataplatform.member.entity.po.tertiary.DataDictory;
import com.liangjian.dataplatform.member.service.IMemberListService;
import com.liangjian.dataplatform.member.service.ITerminaldocService;
import com.liangjian.dataplatform.member.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class TerminaldocService implements ITerminaldocService {

    @Autowired
    private DataDictoryRepository dataDictoryRepository;

    @Autowired
    private MemDataDictoryRepository memDataDictoryRepository;

    @Override
    public List<Map<String, Object>> getgender() {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

        Map<String, Object> map = new HashMap<String, Object>(){{
            put("label", "男");
            put("value", "1");
            put("disabled", false);
        }};
        list.add(map);

        Map<String, Object> map2 = new HashMap<String, Object>(){{
            put("label", "女");
            put("value", "0");
            put("disabled", false);
        }};
        list.add(map2);

        Map<String, Object> map3 = new HashMap<String, Object>(){{
            put("label", "未知");
            put("value", "2");
            put("disabled", false);
        }};
        list.add(map3);

        Map<String, Object> map4 = new HashMap<String, Object>(){{
            put("label", "空");
            put("value", "");
            put("disabled", false);
        }};
        list.add(map4);

        Map<String, Object> map5 = new HashMap<String, Object>(){{
            put("label", "空");
            put("value", "");
            put("disabled", false);
        }};
        list.add(map5);

        return list;
    }

    @Override
    public List<Map<String, Object>> getterms() {
        List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>();
        List<Integer> params = new ArrayList<Integer>();
        params.add(785);
        params.add(786);
        List<DataDictory> list = dataDictoryRepository.findInParentIdAndIsHide(params);
        for (int i = 0; i <list.size() ; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            DataDictory dataDictory = list.get(i);
            String text = dataDictory.getText();
            String value = dataDictory.getValue();
            if(StringUtil.isEmpty(text) || StringUtil.isEmpty(value)){
                continue;
            }
            map.put("label",text);
            map.put("value",value);
            map.put("disabled",false);
            ret.add(map);
        }
        return ret;
    }


    @Override
    public List<Map<String, Object>> getSourcePlatForms() {

        List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>();

        int parentId = 783;
        List<MemDataDictory> list = memDataDictoryRepository.findByParentId(parentId);

        if(!list.isEmpty() && list.size() > 0){
            for (MemDataDictory memDataDictory : list) {
                String text = memDataDictory.getText();
                String value = memDataDictory.getValue();

                if(StringUtil.isEmpty(text) || StringUtil.isEmpty(value)){
                    continue;
                }
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("label",text);
                map.put("value",value);
                map.put("disabled",false);
                ret.add(map);
            }
        }
        return ret;
    }
}
