package com.reyun.saas.mob.user.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONUtil;
import com.reyun.saas.common.constants.*;
import com.reyun.saas.common.core.AbstractService;
import com.reyun.saas.common.exception.CustomException;
import com.reyun.saas.common.model.Constant;
import com.reyun.saas.common.restResult.RestResult;
import com.reyun.saas.common.restResult.ResultCode;
import com.reyun.saas.common.restResult.ResultGenerator;
import com.reyun.saas.common.util.DingDingSendMsgUtil;
import com.reyun.saas.common.util.IPUtils;
import com.reyun.saas.common.util.PatternUtil;
import com.reyun.saas.mob.user.dao.*;
import com.reyun.saas.mob.user.domain.*;
import com.reyun.saas.mob.user.dto.MenuDTO;
import com.reyun.saas.mob.user.dto.user.*;
import com.reyun.saas.mob.user.service.*;
import com.reyun.saas.mob.util.IPAddrUtil;
import com.reyun.saas.mob.util.RoleUtil;
import com.reyun.saas.report.data.dao.DataInfoDayMapper;
import com.reyun.saas.report.data.dao.RtaRequestCountMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.DigestUtils;
import org.springframework.web.client.RestTemplate;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.net.URI;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service
@Transactional
public class UserServiceImpl extends AbstractService<User> implements UserService {

    private static final String  TRACKFLOWMAX =  "trackFlowMax";
    private static final String  SDKHASBEENUSED = "sdkHasBeenUsed";
    private static final String  RTAHAGBEENUSED = "rtaHasBeenUsed";

    @Value("${spring.profiles.active}")
    private String env;
    @Resource
    private UserMapper userMapper;
    @Resource
    private UserAndRoleMapper userAndRoleMapper;
    @Autowired
    private PasswordEncoder passwordEncoder;
    @Resource
    private UserCoreConfigService userCoreConfigService;

    @Resource
    private RtaRequestCountMapper rtaRequestCountMapper;

    @Resource
    private DataInfoDayMapper dataInfoDayMapper;

    @Resource
    private AppMapper appMapper;

    @Resource
    private PackageLevelMapper packageLevelMapper;

    @Resource
    private RtaPackageLevelMapper rtaPackageLevelMapper;

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private MailService mailService;

    @Autowired
    private AuthService authService;

    /**
     * 单点登录系统服务器地址
     */
    @Value("${yuc.host}")
    private String yucHost;

    /**
     * 单点登录系统获取用户信息url
     */
    @Value("${yuc.checkUrl}")
    private String checkUrl;

    /**
     * 单点登录获取用户数据接口的密钥
     */
    private final String yucSecurityKey = "MobDNA";


    /**
     * 根据用户名获取权限信息
     * @param username
     * @return
     */
    @Override
    public UserDTO getRolesByUsername(String username) {
        return userMapper.getRolesByUsername(username);
    }

    /**
     * 添加用户
     * @param inputDTO
     * @param request
     */
    @Override
    public void addUser(UserInputDTO inputDTO, HttpServletRequest request) {
        //校验用户来源
        Integer userSourceType = inputDTO.getUserSourceType();
        UserSourceEnumType enumBykey = UserSourceEnumType.getEnumBykey(userSourceType);
        if (enumBykey == null) {
            throw new CustomException(ResultCode.USER_SOURCE_TYPE_ERROR);
        }

        //校验用户名是否已存在
        Example example = new Example(User.class);
        example.and().andEqualTo("username",inputDTO.getUsername());
        example.and().andEqualTo("delFlag",false);
        User userName = userMapper.selectOneByExample(example);
        if(userName!=null){
            throw new CustomException(ResultCode.EMAIL_ALREADY_EXISTED);
        }
        User user = new User();
        user.setActualName(inputDTO.getActualName());//昵称
        user.setCompany(inputDTO.getCompany());//公司
        user.setPhone(inputDTO.getPhone());//手机号
        user.setQq(inputDTO.getQq());//QQ
        user.setUsername(inputDTO.getUsername());//邮箱(唯一的)
        user.setWechat(inputDTO.getWechat());//微信
        user.setSex(inputDTO.getSex());
        user.setHeadPortrait("avatar"+RandomUtil.randomInt(1,27));//随机生存头像  头像在数据库中格式: avater+ 1 ~ 26数字
        user.setPassword(passwordEncoder.encode(inputDTO.getPassword()));
        // 默认待审核
        user.setStatus(Constant.STATUS_AUDITED);
        user.setCreateTime(new Date());
        user.setRootParent(0L);
        user.setModifyTime(new Date());
        user.setOid(SecureUtil.md5(user.getUsername()+user.getCreateTime().getTime()));
        user.setRoleCategory(RoleEnumType.SUPER_USER.getKey());
        user.setIsCreateApp(true);
        user.setAuthConfig(true);
        user.setDelFlag(false);
        user.setLeaderParent(0L);
        user.setUserSource(enumBykey.getCode());//设置用户来源
        userMapper.insertSelective(user);
        if(env.equals("pro")){//生产环境生效
            StringBuilder sb = new StringBuilder("公司：");
            sb
                    .append(user.getCompany()).append("\n")
                    .append("邮箱：").append(user.getUsername()).append("\n")
                    .append("姓名：").append(user.getActualName()).append("\n")
                    .append("电话：").append(user.getPhone()).append("\n")
                    .append("微信：").append(user.getWechat()).append("\n")
                    .append("QQ：").append(user.getQq()).append("\n")
                    .append("IP归属地：").append(IPAddrUtil.getLocationFromIpAddr(request));
            sendDingDing(sb.toString());
        }
    }

    @Async
    public void sendDingDing(String content){
        DingDingSendMsgUtil dingDingSendMsgUtil = new DingDingSendMsgUtil(DingDingSendMsgUtil.TOKEN_USER_REG_MSG, DingDingSendMsgUtil.KEY_USER_REG_MSG);
        dingDingSendMsgUtil.sendMsg(content);
    }


    /**
     * 批量冻结用户
     * @param ids
     */
    @Override
    public void frozeUser(String ids, Integer status) {
        List<String> Ids = Arrays.stream(ids.split(",")).collect(Collectors.toList());
        Example example = new Example(User.class);
        example.and().andIn("id", Ids);
        List<User> users = userMapper.selectByExample(example);
        for (User user :users) {
            user.setStatus(status);
            user.setModifyTime(new Date());
            userMapper.updateByPrimaryKeySelective(user);
        }
    }

    /**
     * 获取用户明细
     * @param id
     * @return
     */
    @Override
    public UserOutpDTO findOne(Long id) {
        User user = userMapper.selectByPrimaryKey(id);
        if (null == user){
            throw new CustomException(ResultCode.USER_NOT_EXIST);
        }
        Example example = new Example(UserAndRole.class);
        example.and().andEqualTo("userId", id);
        List<UserAndRole> userAndRoles = userAndRoleMapper.selectByExample(example);

        Set<Long> roleSet = new HashSet<>();
        userAndRoles.stream().forEach(e ->
            roleSet.add(e.getRoleId())
        );
        UserOutpDTO outpDTO = new UserOutpDTO();
        BeanUtils.copyProperties(user, outpDTO);
        outpDTO.setRoleIds(StringUtils.join(roleSet, ","));
        //查询过期时间
        Long rootId = RoleEnumType.SUPER_USER.getKey().equals(user.getRoleCategory())?user.getId():user.getRootParent();
        UserCoreConfigDTO byRootParent = userCoreConfigService.findByRootParent(rootId);
        outpDTO.setPastDate(byRootParent.getPastDate());
        return outpDTO;
    }

    /**
     * 修改用户信息
     * @param inputDTO
     */
    @Override
    public RestResult updateUser(UserInputDTO inputDTO,Long userId) {

        if(inputDTO == null){
            return ResultGenerator.genResult(ResultCode.PARAMETER_ERROR);
        }

        User user = userMapper.selectByPrimaryKey(userId);
        user.setId(userId);//用户id
        user.setModifyTime(new Date()); //修改时间
        user.setModifyUser(userId);//修改人
        user.setWechat(inputDTO.getWechat());//微信号
        user.setActualName(inputDTO.getActualName());//名称
        user.setHeadPortrait(inputDTO.getHeadPortrait());//头像

        //校验手机号
        if(org.springframework.util.StringUtils.isEmpty(user.getPhone())
                || org.springframework.util.StringUtils.isEmpty(user.getPhone().trim())){
            //目标手机号不能为空
            if(PatternUtil.isMobileNo(inputDTO.getPhone())){
                user.setPhone(inputDTO.getPhone());
            }else{
                return ResultGenerator.genResult(ResultCode.PHONE_FORMAT_ERROR);
            }
        }

        userMapper.updateByPrimaryKeySelective(user);
        return ResultGenerator.genSuccessResult();
    }


    /**
     * 修改用户密码
     * @param dto
     */
    @Override
    public void updateUserPwd(UserPwdDTO dto) {
        User user = userMapper.selectByPrimaryKey(dto.getId());
        boolean matches = passwordEncoder.matches(dto.getPassword(), user.getPassword());
        if (!matches){
            throw new CustomException(ResultCode.OLD_PASSWORD_ERROR);
        }
        String encodePwd = passwordEncoder.encode(dto.getNewPassword());
        user.setPassword(encodePwd);
        user.setModifyTime(new Date());

        //将临时随机密码过期时间字段改为 -1
        user.setRandomPwdPastTime("-1");

        //如果是处于未激活状态  在修改密码时改为已激活
        if(user.getStatus().equals(UserStatusEnum.USER_NONACTIVATED.getStatus())){
            user.setStatus(UserStatusEnum.USER_IS_NORMAL.getStatus());
        }

        userMapper.updateByPrimaryKeySelective(user);
    }


    /**
     * 忘记密码 邮件发送随机密码
     */
    @Override
    public RestResult emailResetPwd(HttpServletRequest request,String email) {

        if (org.springframework.util.StringUtils.isEmpty(email)) {
            return ResultGenerator.genResult(ResultCode.PARAMETER_ERROR);
        }

        //该接口是开放的  简单的防刷处理  同一个邮箱60秒内只能发送一次
        Boolean send = mailService.isRepetitionSend(email);
        if (!send) {
            return new RestResult(ResultCode.SERVER_BUSY);
        }

        Example example = new Example(User.class);
        example.and().andEqualTo("username",email);
        example.and().andEqualTo("delFlag",false);
        User user = userMapper.selectOneByExample(example);

        if (user == null) {
            //用户不存在
            return new RestResult(ResultCode.USER_NOT_EXIST);
        }

        //生成10位的随机密码
        String randomPwd = RandomUtil.randomString(10);
        user.setPassword(passwordEncoder.encode(randomPwd));

        //获取一天后的时间
        Calendar instance = Calendar.getInstance();
        instance.add(Calendar.DATE,1);
        String format = DateUtil.format(instance.getTime(), "yyyy-MM-dd HH:mm:ss");
        user.setRandomPwdPastTime(format);

        //修改密码
        userMapper.updateByPrimaryKeySelective(user);

        boolean succeed = false;
        try {
            succeed = mailService.sendNewPwd(user, randomPwd, MailEnumType.FORGETPWD);
            if (succeed){
                log.info("发送临时随机密码成功! 邮箱:{} 临时密码:{}",user.getUsername(),randomPwd);
            }
        } catch (Exception exception) {
            log.error("忘记密码邮件发送失败! 邮箱:{} 异常信息:{}", user.getUsername(),exception.getMessage());
            throw new RuntimeException();
        }
        return succeed?ResultGenerator.genSuccessResult():ResultGenerator.genFailResult("");
    }

    /**
     * 判断用户名密码是否正确
     * @param username
     * @param password
     * @return
     */
    private Boolean checkUser(String username, String password){
        User user = this.findBy("username", username);
        return passwordEncoder.matches(password, user.getPassword());
    }

    /**
     * 获取用户权限
     * @return
     */
    @Override
    public List<MenuDTO> getUserMenus(Long userId) {
        // return menuRightMapper.getMenusByUserId(userId);
        return null;
    }

    @Override
    public UserOutpDTO findUserByOnly(String key, String val) {
        Example example = new Example(User.class);
        example.and().andEqualTo(key,val);
        example.and().andEqualTo("delFlag",false);
        User user = userMapper.selectOneByExample(example);
        if (null == user){
            throw new CustomException(ResultCode.USER_NOT_EXIST);
        }
        UserOutpDTO outpDTO = new UserOutpDTO();
        BeanUtils.copyProperties(user, outpDTO);
        return outpDTO;
    }

    @Override
    public List<Map<String,Object>> findMyselfAndChSubordinate(Long loginUserId) {
        User user = userMapper.selectByPrimaryKey(loginUserId);
        List<Map<String,Object>> usersMap = new ArrayList<>();
        Map<String,Object> userMap = new HashMap<>();
        userMap.put("id",user.getId());
        userMap.put("username",user.getUsername());
        userMap.put("actualName",user.getActualName());
        userMap.put("phone",user.getPhone());
        usersMap.add(userMap);

        Long rootId = RoleEnumType.SUPER_USER.getKey().equals(user.getRoleCategory())?user.getId():user.getRootParent();

        Example example = new Example(User.class);
        if(RoleEnumType.SUPER_USER.getKey().equals(user.getRoleCategory())){
            //主账号
            example.and().andEqualTo("rootParent",rootId);
            example.and().andEqualTo("delFlag",false);

        }else if(RoleEnumType.MANAGER.getKey().equals(user.getRoleCategory())){
            //管理员
            example.and().andEqualTo("rootParent",rootId);
            example.and().andEqualTo("delFlag",false);
            example.and().orNotEqualTo("roleCategory",RoleEnumType.MANAGER.getKey());
        }else if(RoleEnumType.SUB_APP_MANAGER.getKey().equals(user.getRoleCategory())){
            //子应用管理员
            example.and().andEqualTo("rootParent",rootId);
            example.and().andEqualTo("leaderParent",user.getId());
            example.and().andEqualTo("delFlag",false);
        }


        List<User> users = userMapper.selectByExample(example);
        for (User user1 : users) {
            Map<String,Object> map = new HashMap<>();
            map.put("id",user1.getId());
            map.put("username",user1.getUsername());
            map.put("actualName",user1.getActualName());
            map.put("phone",user1.getPhone());
            usersMap.add(map);
        }

        return usersMap;
    }



    @Override
    public RestResult flowInfo(Long userId) {
        User user = userMapper.selectByPrimaryKey(userId);
        if (user == null) {
            return ResultGenerator.genResult(ResultCode.USER_NOT_EXIST);
        }

        //获取主用户的核心配置
        UserCoreConfig userCoreConfig = userCoreConfigService.findRootCoreConfig(user);

        //获取用户流量使用情况
        Map<String, Long> flowInfoByUser = findFlowInfoByUser(user, userCoreConfig);

        Long sdkHasBeenUsed = flowInfoByUser.get(SDKHASBEENUSED);//sdk上报次数
        Long rtaHasBeenUsed = flowInfoByUser.get(RTAHAGBEENUSED);//rta请求次数

        //封装结果集  根据不同的角色返回不同的数据
        Map<String,Object> result = new HashMap<>();
        result.put(SDKHASBEENUSED,sdkHasBeenUsed);
        result.put(RTAHAGBEENUSED,rtaHasBeenUsed);
        if (RoleUtil.isSuperUserOrManager(user)) {
            //主账号 或者 管理员
            result.put(TRACKFLOWMAX,userCoreConfig.getTrackFlow());
            //查询套餐  获取套餐名称
            PackageLevel packageLevel = packageLevelMapper.selectByPrimaryKey(userCoreConfig.getPackageLevelId());
            Map<String,Object> resPackageLevel = new HashMap<>();
            resPackageLevel.put("packageName",packageLevel.getPackageName());
            result.put("packageLevel",resPackageLevel);
        }


        return ResultGenerator.genSuccessResult(result);
    }


    /**
     * 校验流量
     * @param userOutpDTO 目标用户
     * @return  流量未用尽为true 流量用尽为false
     */
    @Override
    public Boolean checkFlow(UserOutpDTO userOutpDTO) {
        User user = new User();
        BeanUtils.copyProperties(userOutpDTO,user);

        //用户核心配置
        UserCoreConfig rootCoreConfig = userCoreConfigService.findRootCoreConfig(user);
        Long trackFlowMax = rootCoreConfig.getTrackFlow();

        //判断无限流量
        if(trackFlowMax.equals(-1L)){
            //流量无限
            return true;
        }
        Map<String, Long> flowInfoByUser = findFlowInfoByUser(user, rootCoreConfig);
        Long sdkHasBeenUsed = flowInfoByUser.get(SDKHASBEENUSED);
        Long rtaHasBeenUsed = flowInfoByUser.get(RTAHAGBEENUSED);


        //todo 当前流量校验为 : rta请求次数加sdk上报次数 对比该用户套餐的最大流量
        if((sdkHasBeenUsed+rtaHasBeenUsed)>trackFlowMax){
            //流量用尽
            return false;
        }

        //流量没用尽
        return true;
    }

    @Override
    public RestResult yunUserInfo(HttpServletRequest request,Map<String,Object> map) {

        String secret = (String)map.get("secret");
        String email = (String)map.get("email");
        //校验单点登录系统ip
        String remoteAddr = IPUtils.getIpAddr(request).split(",")[0];
        if(!yucHost.equals(remoteAddr)){
            log.error("单点登录系统ip校验失败! ip: "+remoteAddr);
            return new RestResult(4000,"拒绝访问!");
        }

        //校验密钥
        String key = DigestUtils.md5DigestAsHex(yucSecurityKey.getBytes());
        if (!secret.equals(key)) {
            log.error("单点登录系统密钥错误! secret: "+secret);
            return new RestResult(4000,"拒绝访问");
        }

        //查询用户
        Example example = new Example(User.class);
        example.and().andEqualTo("username", email);
        User user = userMapper.selectOneByExample(example);
        if (user == null) {
            log.error("单点登录用户不存在! email: "+email);
            return new RestResult(4000,"用户不存在");
        }

        // 账号状态：0-禁用，1-启用，2-待审核，3-过期，4-流量用尽  除了用户启用其他的都传false
        String isActive = user.getStatus().equals(1)?"true":"false";


        //封装参数
        Map<String,Object> result = new HashMap<>();
        //应单点登录技术人员的要求 info为null
        result.put("info",null);
        result.put("userName",user.getActualName());//用户名
        result.put("company",user.getCompany());//公司
        result.put("regType","EMAIL");//注册类型
        result.put("userType","");//用户类型
        result.put("userMaster",user.getRoleCategory()+"");//是否是主账号
        result.put("phone",user.getPhone());//手机号
        result.put("emailAddress",user.getUsername());//邮箱
        result.put("engyptPassword","");//加密后的密码
        result.put("department","");//部门
        result.put("industry","");//岗位
        result.put("position","");//行业
        result.put("effectDate","");//
        result.put("expireDate","");//过期时间
        result.put("createTime",user.getCreateTime());//创建时间
        result.put("yn",isActive);//是否可用

        log.info("单点登录系统获取信息成功! ip:{} email:{}",remoteAddr,email);
        return new RestResult(2000,"操作成功",result);

    }

    @Override
    public UserOutpDTO getUserFormYun(String yucToken) {
        //设置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        String secret = DigestUtils.md5DigestAsHex(yucSecurityKey.getBytes());

        Map<String,Object> body = new HashMap<>();
        body.put("token",yucToken);
        body.put("sysCode",yucSecurityKey);
        body.put("sysSecret",secret);

        String bodyJson = JSONUtil.toJsonStr(body);

        HttpEntity<String> entity = new HttpEntity<String>(bodyJson, headers);

        String emailAddress = null;
        try {
            String json = restTemplate.postForObject(URI.create(checkUrl), entity, String.class);
            Map map = JSONUtil.toBean(json, Map.class);
            String code = (String)map.get("code");
            if("2000".equals(code)){
                //成功
                Map<String,Object> data = (Map<String,Object>)map.get("data");
                emailAddress = (String)data.get("emailAddress");
                return findUserByOnly("username", emailAddress);
            }else{
                //失败
                return null;
            }

        } catch (Exception e) {
            log.error("请求单点登录系统获取用户信息失败! ",e);
            return null;
        }
    }

    /**
     * 校验临时随机密码是否过期
     * @param userOutpDTO 被校验用户
     * @return  允许登录为true 拒绝登录为false
     */
    @Override
    public Boolean checkRandomPwdPast(UserOutpDTO userOutpDTO) {

        String randomPwdPastTime = userOutpDTO.getRandomPwdPastTime();
        if(org.springframework.util.StringUtils.isEmpty(randomPwdPastTime) || "-1".equals(randomPwdPastTime)){
            //randomPwdPastTime字段为空 或者为-1 标识该用户的密码不是临时随机密码
            return true;
        }else{

            //临时随机密码过期时间
            Long userRandomPwdPathTime = DateUtil.parse(randomPwdPastTime).getTime();

            //当前时间
            Long currentTime= System.currentTimeMillis();
            if(currentTime>userRandomPwdPathTime){
                //简单的防刷
                Boolean send = mailService.isRepetitionSend(userOutpDTO.getUsername());
                if(!send){
                    throw new CustomException(ResultCode.SERVER_BUSY);
                }

                //发送邮件给用户重置随机密码
                User user = new User();
                user.setId(userOutpDTO.getId());
                user.setModifyTime(new Date());
                user.setModifyUser(userOutpDTO.getId());
                user.setUsername(userOutpDTO.getUsername());
                //随机密码超时时间
                Calendar instance = Calendar.getInstance();
                instance.add(Calendar.DATE,1);
                String format = DateUtil.format(instance.getTime(), "yyyy-MM-dd HH:mm:ss");
                user.setRandomPwdPastTime(format);

                //生成10位的随机密码
                String randomPwd = RandomUtil.randomString(10);
                user.setPassword(passwordEncoder.encode(randomPwd));
                userMapper.updateByPrimaryKeySelective(user);

                try {
                    Boolean aBoolean = mailService.sendNewPwd(user, randomPwd, MailEnumType.PWDPAST);
                    if (aBoolean) {
                        log.info("发送临时随机密码成功! 邮箱:{} 临时密码:{}",user.getUsername(),randomPwd);
                    }
                } catch (Exception exception) {
                    log.error("临时密码过期重发失败! 邮箱:{}", user.getUsername(),exception);
                }
                return false;
            }else{
                return true;
            }
        }
    }


    /**
     * 根据用户查找流量使用情况
     * @param user 目标用户
     * @return 流量使用情况
     */
    private Map<String,Long> findFlowInfoByUser(User user, UserCoreConfig userCoreConfig){

        List<String> appkeys = new ArrayList<>();
        List<App> appByUser = authService.getAppByUserIncludeDel(user);
        appByUser.forEach(v -> {appkeys.add(v.getAppkey());});

        //如果这个用户没有app 添加-1 防止sql报错
        if (CollectionUtils.isEmpty(appkeys)) {
            appkeys.add("-1");
        }

        //获取昨天的时间
        String yesterday = DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd");

        Long sdkHasBeenUsed = dataInfoDayMapper.findSDKReportCount(appkeys, yesterday, userCoreConfig.getPubDate());

        //todo 后续rta请求次数表增加appkey留意这里
        Long rtaHasBeenUsed =  rtaRequestCountMapper.findRtaReqCountByOid(user.getOid(), yesterday, userCoreConfig.getPubDate());

        sdkHasBeenUsed = sdkHasBeenUsed==null?0L:sdkHasBeenUsed;
        rtaHasBeenUsed = rtaHasBeenUsed==null?0L:rtaHasBeenUsed;

        Map<String,Long> result = new HashMap<>();
        result.put(SDKHASBEENUSED,sdkHasBeenUsed);
        result.put(RTAHAGBEENUSED,rtaHasBeenUsed);

        return result;
    }

}
