package com.fs.framework.utils;


import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fs.company.domain.Company;
import com.fs.company.domain.CompanyUser;
import com.fs.framework.security.LoginCompanyUser;
import com.fs.framework.security.LoginUser;

import java.util.stream.Collectors;

public class LoginUserUtils {
    public static LoginUser getLoginCompanyUse(Object o) {
        JSONObject user = JSONObject.parseObject(JSON.toJSONString(o));
//        LoginCompanyUser loginCompanyUser = new LoginCompanyUser();
        LoginUser loginCompanyUser = new LoginUser();
        loginCompanyUser.setToken(user.get("token").toString());
        loginCompanyUser.setLoginTime(Long.valueOf(user.get("loginTime").toString()));
        loginCompanyUser.setExpireTime(Long.valueOf(user.get("expireTime").toString()));
        loginCompanyUser.setIpaddr(user.get("ipaddr").toString());
        loginCompanyUser.setLoginLocation(user.get("loginLocation").toString());
        loginCompanyUser.setBrowser(user.get("browser").toString());
        loginCompanyUser.setOs(user.get("os").toString());
        loginCompanyUser.setPermissions(JSON.parseArray(user.get("permissions").toString(),String.class).stream().collect(Collectors.toSet()));
        loginCompanyUser.setUser(JSONObject.parseObject(user.get("user").toString(), CompanyUser.class));
        loginCompanyUser.setCompany(JSONObject.parseObject(user.get("company").toString(), Company.class));

        return loginCompanyUser;
    }
}
