package com.qmth.themis.business.cache;

import com.qmth.themis.business.constant.SpringContextHolder;
import com.qmth.themis.business.enums.ExamBreakHistoryFieldEnum;
import com.qmth.themis.business.enums.ExceptionEnum;
import com.qmth.themis.business.enums.VerifyExceptionEnum;
import com.qmth.themis.business.util.RedisUtil;

import java.util.Objects;

/**
 * 断点缓存hash值操作
 *
 * @Description:
 * @Author: xiatian
 * @Long: 2020-07-29
 */
public class ExamBreakCacheUtil {
    private static RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);

    public static void setExamRecordId(Long examBreakId, Long examRecordId) {
        redisUtil.set(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.exam_record_id.getCode(), examRecordId);
    }

    public static Long getExamRecordId(Long examBreakId) {
        return (Long) redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.exam_record_id.getCode());
    }

    public static void setBreakTime(Long examBreakId, Long breakTime) {
        redisUtil.set(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.break_time.getCode(), breakTime);
    }

    public static Long getBreakTime(Long examBreakId) {
        return (Long) redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.break_time.getCode());
    }

    public static void setBreakReason(Long examBreakId, ExceptionEnum breakReason) {
        redisUtil.set(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.break_reason.getCode(), breakReason);
    }

    public static ExceptionEnum getBreakReason(Long examBreakId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.break_reason.getCode())) ? ExceptionEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.break_reason.getCode())) : null;
    }

    public static void setResumeReason(Long examBreakId, String resumeReason) {
        redisUtil.set(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.resume_reason.getCode(), resumeReason);
    }

    public static String getResumeReason(Long examBreakId) {
        return (String) redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.resume_reason.getCode());
    }

    public static void setPrepareTime(Long examBreakId, Long prepareTime) {
        redisUtil.set(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.prepare_time.getCode(), prepareTime);
    }

    public static Long getPrepareTime(Long examBreakId) {
        return (Long) redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.prepare_time.getCode());
    }

    public static void setStartTime(Long examBreakId, Long startTime) {
        redisUtil.set(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.start_time.getCode(), startTime);
    }

    public static Long getStartTime(Long examBreakId) {
        return (Long) redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.start_time.getCode());
    }

    public static void setEntryAuthenticationResult(Long examBreakId, VerifyExceptionEnum entryAuthenticationResult) {
        redisUtil.set(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.entry_authentication_result.getCode(), entryAuthenticationResult);
    }

    public static VerifyExceptionEnum getEntryAuthenticationResult(Long examBreakId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.entry_authentication_result.getCode())) ? VerifyExceptionEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.entry_authentication_result.getCode())) : null;
    }

    public static void setEntryAuthenticationId(Long examBreakId, Long entryAuthenticationId) {
        redisUtil.set(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.entry_authentication_id.getCode(), entryAuthenticationId);
    }

    public static Long getEntryAuthenticationId(Long examBreakId) {
        return (Long) redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.entry_authentication_id.getCode());
    }
}