/**
 *
 */
package com.uc.demo;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.google.gson.Gson;
import com.huawei.esdk.uc.professional.local.bean.RestRequestMessage;
import com.huawei.esdk.uc.professional.local.bean.RestResponse;
import com.huawei.esdk.uc.professional.local.bean.south.QueryUCListPresenceRequest;
import com.huawei.esdk.uc.professional.local.bean.south.UserState;
import com.huawei.esdk.uc.professional.local.service.PresenceServiceEx;
import com.huawei.esdk.uc.professional.local.serviceImpl.PresenceServiceExImpl;
import com.huawei.esdk.uc.professional.local.utils.RestUtils;

/**
 * 
 * @team BBDTEK IT Team
 * @author renmb
 * @version 1.0
 * @time  2016年10月28日
 */
public class UCStateDemoMain {

    /**
     * 查看用户状态接口
     * @author renmb
     * @time  2016年10月28日
     * @param args
     */
    public static void main(String[] args) {
        

        List<String> queryUsers = new ArrayList<String>();
        for(int i=0,len=args.length;i<len;i++){
            
            queryUsers.add(args[i]);
        }
        PresenceServiceEx impl = PresenceServiceExImpl.getInstance();
        QueryUCListPresenceRequest req = new QueryUCListPresenceRequest();
        req.setUser("123");
        req.setQueryUsers(queryUsers);
        RestResponse<List<UserState>> list = impl.queryUCListPresence(req);
        if(list != null && list.getResult() != null){
            
            List<UserState> users = list.getResult();
            Gson gson = new Gson();
            System.out.println("查询结果: "+gson.toJson(users));
//            for(UserState state:users){
//                
//                System.out.println("状态："+users.get(0).getNewState());
//            }
//            if(users.size()>0){
//                
//                System.out.println("状态："+users.get(0).getNewState());
//            }
        }
        System.exit(0);
        
        // TODO Auto-generated method stub
        RestRequestMessage restRequestMessage = new RestRequestMessage();
        restRequestMessage.setHttpMethod("POST");
//        List<String> queryUsers = new ArrayList<String>();
//        queryUsers.add("1000022197");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("user", "123");
        params.put("queryUsers", queryUsers);
        restRequestMessage.setPayload(params);
        RestUtils restUtils = RestUtils.getInstance();
        try {
            String res = restUtils.sendMessage(restRequestMessage, "/ec/eserver/presence");
            
            System.out.println(res);
            if (StringUtils.isNotBlank(res)) {
//                LOG.debug("----------------         HUAWEI PERSON          -------------------" + res);
                Gson gson = new Gson();
//                HuaweiUserStatResult result = gson.fromJson(res, HuaweiUserStatResult.class);
//                if (result != null && result.getResultCode().equals("0")
//                        && result.getUserStates() != null && result.getUserStates().size() > 0) {
//                    return result.getUserStates().get(0);
//                }
            } else {
//                LOG.debug("----------------         HUAWEI PERSON NULL         -------------------");
            }
        } catch (URISyntaxException | IOException e) {
//            e.printStackTrace();
        }
//        return null;
    }

}
