package com.qmth.themis.business.cache;

import com.qmth.themis.business.constant.SpringContextHolder;
import com.qmth.themis.business.constant.SystemConstant;
import com.qmth.themis.business.enums.MobileModeEnum;
import com.qmth.themis.business.enums.MonitorVideoSourceEnum;
import com.qmth.themis.business.util.RedisUtil;

import java.util.Objects;

/**
 * 移动端临时认证
 *
 * @Description:
 * @Author: xiatian
 * @Date: 2020-08-14
 */
public class MobileAuthCacheUtil {

    private static RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);

    public static void setUserType(MobileModeEnum mode, String code, String userType) {
        redisUtil.set(RedisKeyHelper.mobileAuthCacheKey(mode, code), "userType", userType);
    }

    public static void setMode(MobileModeEnum mode, String code) {
        redisUtil.set(RedisKeyHelper.mobileAuthCacheKey(mode, code), "mode", mode);
    }

    public static MobileModeEnum getMode(MobileModeEnum mode, String code) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "mode")) ? MobileModeEnum.valueOf((String) redisUtil.get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "mode")) : null;
    }

    public static void deleteMode(MobileModeEnum mode, String code) {
        redisUtil.delete(RedisKeyHelper.mobileAuthCacheKey(mode, code));
    }

    public static void setCode(MobileModeEnum mode, String code) {
        redisUtil.set(RedisKeyHelper.mobileAuthCacheKey(mode, code), "code", code);
    }

    public static String getCode(MobileModeEnum mode, String code) {
        return (String) redisUtil.get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "code");
    }

    public static void setRecordId(MobileModeEnum mode, String code, Long recordId) {
        redisUtil.set(RedisKeyHelper.mobileAuthCacheKey(mode, code), SystemConstant.RECORD_ID, recordId);
    }

    public static Long getRecordId(MobileModeEnum mode, String code) {
        return (Long) redisUtil.get(RedisKeyHelper.mobileAuthCacheKey(mode, code), SystemConstant.RECORD_ID);
    }

    public static void setMainNumber(MobileModeEnum mode, String code, Integer mainNumber) {
        redisUtil.set(RedisKeyHelper.mobileAuthCacheKey(mode, code), "mainNumber", mainNumber);
    }

    public static Integer getMainNumber(MobileModeEnum mode, String code) {
        return (Integer) redisUtil.get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "mainNumber");
    }

    public static void setSubNumber(MobileModeEnum mode, String code, Integer subNumber) {
        redisUtil.set(RedisKeyHelper.mobileAuthCacheKey(mode, code), "subNumber", subNumber);
    }

    public static Integer getSubNumber(MobileModeEnum mode, String code) {
        return (Integer) redisUtil.get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "subNumber");
    }

    public static void setSubIndex(MobileModeEnum mode, String code, Integer subIndex) {
        redisUtil.set(RedisKeyHelper.mobileAuthCacheKey(mode, code), "subIndex", subIndex);
    }

    public static Integer getSubIndex(MobileModeEnum mode, String code) {
        return (Integer) redisUtil.get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "subIndex");
    }

    public static void setMonitorVideoSource(MobileModeEnum mode, String code,
                                             MonitorVideoSourceEnum monitorVideoSource) {
        redisUtil.set(RedisKeyHelper.mobileAuthCacheKey(mode, code), "monitorVideoSource", monitorVideoSource);
    }

    public static MonitorVideoSourceEnum getMonitorVideoSource(MobileModeEnum mode, String code) {
        return Objects.nonNull(redisUtil
                .get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "monitorVideoSource")) ? MonitorVideoSourceEnum.valueOf((String) redisUtil
                .get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "monitorVideoSource")) : null;
    }

    public static String getUserType(MobileModeEnum mode, String code) {
        return (String) redisUtil.get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "userType");
    }

    public static void setQuestionNumber(MobileModeEnum mode, String code, String questionNumber) {
        redisUtil.set(RedisKeyHelper.mobileAuthCacheKey(mode, code), "questionNumber", questionNumber);
    }

    public static String getQuestionNumber(MobileModeEnum mode, String code) {
        return (String) redisUtil.get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "questionNumber");
    }
}
