package com.handong.smartservice.component;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.handong.smartservice._AG;

public class RcTreeBizGroup extends RcTree {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    public static List<Map<String, Object>> convertDb2RcTree(List<Map<String, Object>> listTreeDb) {
        RcTree rcTree = new RcTreeBizGroup();
        return rcTree.convert(listTreeDb);
    }

    @Override
    protected Map<String, Object> makeNewNode(Map<String, Object> item) {
        Map<String, Object> newNode = new LinkedHashMap<String, Object>();

        String biz_group_id = item.get("biz_group_id").toString();
        newNode.put("key", biz_group_id);
        logger.debug("key(biz_group_id): " + biz_group_id);

        String name = (String)item.get("name");
        newNode.put("name", name);

        String biz_reg_num = _AG.formatBusinessNumber((String)item.get("biz_reg_num"));
        newNode.put("biz_reg_num", biz_reg_num);            
        
        //... newNode.put("title", name + "(" + biz_reg_num + ")");
        newNode.put("title", name);
        logger.debug("title(name): " + name);

        Timestamp reg_time = (Timestamp)item.get("reg_time");
        if (reg_time != null)
            newNode.put("reg_time", reg_time);

        String email = (String)item.get("email");
        if (email != null)
            newNode.put("email", email);
        
        String phone = (String)item.get("phone");
        if (phone != null)
            newNode.put("phone", phone);
        
        String ceo = (String)item.get("ceo");
        if (ceo != null)
            newNode.put("ceo", ceo);

        String address = (String)item.get("address");
        if (address != null)
            newNode.put("address", address);

        Long top_group_id = (Long)item.get("top_group_id");
        if (address != null)
            newNode.put("top_group_id", top_group_id);

        Long hasChildren = (Long)item.get("hasChildren");
        newNode.put("isLeaf", hasChildren == null || hasChildren == 0 ? true : false);
            
        return newNode;
    }
}
