package com.ghy.message.service.impl;

import cn.jmessage.api.JMessageClient;
import cn.jmessage.api.common.model.RegisterInfo;
import com.ghy.message.config.JimConfig;
import com.ghy.message.domain.JimUser;
import com.ghy.message.service.JimUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 极光推送用户impl
 * @author clunt
 */
@Slf4j
@Service
public class JimUserServiceImpl implements JimUserService {

    @Resource
    private JimConfig jimConfig;

    @Override
    public int registerJimUser(JimUser jimUser) throws Exception{
        JMessageClient messageClient = new JMessageClient(jimConfig.getAppKey(),jimConfig.getMasterSecret());
        RegisterInfo.Builder builder = new RegisterInfo.Builder();
        builder.setUsername(jimUser.getUserName());
        builder.setPassword(jimUser.getPassword());
        RegisterInfo [] registerInfos = new RegisterInfo[1];
        registerInfos[0] = builder.build();
        String result =  messageClient.registerUsers(registerInfos);
        return 0;
    }

}
