package com.axis.innovators.box.util;

import com.axis.innovators.box.AxisInnovatorsBox;
import com.axis.innovators.box.verification.OnlineVerification;
import com.axis.innovators.box.verification.UserTags;
import com.axis.innovators.box.verification.VerificationService;

/**
 * 用于存储用户信息
 * @author tzdwindows 7
 */
public class UserLocalInformation {
    private final AxisInnovatorsBox main;

    public UserLocalInformation(AxisInnovatorsBox main){
        this.main = main;
    }

    /**
     * 设置用户信息
     * @param userTags 用户信息
     */
    public void setUserTags(UserTags userTags){
        OnlineVerification onlineVerification = userTags.getUser();
        main.getStateManager().saveState("password", onlineVerification.password);
        main.getStateManager().saveState("verification", onlineVerification.onlineVerification);
    }

    /**
     * 获取用户信息
     * @return 用户信息
     */
    public UserTags getUserTags(){
        String verification = main.getStateManager().getState("verification");
        String password = main.getStateManager().getState("password");
        if (verification == null || password == null){
            return null;
        }
        OnlineVerification onlineVerification = OnlineVerification.validateLogin(
                verification,
                password);
        return VerificationService.determineUserType(onlineVerification);
    }
}
