package org.springblade.common.cache;

import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.flow.mall.entity.MallInvitationCallbackVO;
import org.springblade.flow.shop.entity.AuthInfoData;
import org.springblade.flow.shop.entity.InvitationCallbackVO;
import org.springblade.ldt.shop.dto.ArtificialAuthInfoData;

import java.util.Set;

/**
 * @author: lianghanqiang
 * @description:
 * @since: 9/7/21 -- 10:52 AM
 */
public class FlowCache {
	private static BladeRedis bladeRedis;
	private static final String SHOP_AUDIT_PREFIX = "shop_audit";
	private static final String Mall_AUDIT_PREFIX = "Mall_audit";
	private static final String AUTH_LIST_KEY = "wechat_auth";
	private static final String ARTIFICIAL_AUTH_LIST_KEY = "artificial_wechat_auth";

	static {
		bladeRedis = SpringUtil.getBean(BladeRedis.class);
	}

	/**
	 * 缓存入网申请数据
	 */
	public static void putAudit(InvitationCallbackVO data, String invitationId) {
		CacheUtil.put(CacheNames.FLOW, SHOP_AUDIT_PREFIX, invitationId, data, false);
	}

	/**
	 * 入网申请数据
	 */
	public static InvitationCallbackVO getAudit(String invitationId) {
		return CacheUtil.get(CacheNames.FLOW, SHOP_AUDIT_PREFIX, invitationId, InvitationCallbackVO.class, false);
	}

	/**
	 * 移除入网申请数据
	 */
	public static void removeAudit(String invitationId) {
		CacheUtil.evict(CacheNames.FLOW, SHOP_AUDIT_PREFIX, invitationId, false);
	}

	/**
	 * 缓存商场申请数据
	 */
	public static void putMallAudit(MallInvitationCallbackVO data, String invitationId) {
		CacheUtil.put(CacheNames.FLOW, Mall_AUDIT_PREFIX, invitationId, data, false);
	}

	/**
	 * 缓存商场申请数据
	 */
	public static MallInvitationCallbackVO getMallAudit(String invitationId) {
		return CacheUtil.get(CacheNames.FLOW, Mall_AUDIT_PREFIX, invitationId, MallInvitationCallbackVO.class, false);
	}

	/**
	 * 移除商场入网申请数据
	 */
	public static void removeMallAudit(String invitationId) {
		CacheUtil.evict(CacheNames.FLOW, Mall_AUDIT_PREFIX, invitationId, false);
	}

	/***
	 * 	微信认证队列--添加成员
	 * */
	public static void addAuthMember(AuthInfoData authInfoData) {
		bladeRedis.sAdd(CacheNames.PAYMENT + ":" + AUTH_LIST_KEY, authInfoData);
	}

	/***
	 * 	获取-- 微信认证队列
	 *
	 * @return*/
	public static Set<AuthInfoData> authList() {
		Set<AuthInfoData> authList = bladeRedis.sMembers(CacheNames.PAYMENT + ":" + AUTH_LIST_KEY);
		return authList;
	}

	/***
	 * 	微信认证队列--移除成员
	 * */
	public static void removeAuthMember(AuthInfoData... authInfoData) {
		bladeRedis.sRem(CacheNames.PAYMENT + ":" + AUTH_LIST_KEY, authInfoData);
	}

	/***
	 * 	人工微信认证队列--添加成员
	 * */
	public static void addArtificialAuthMember(ArtificialAuthInfoData authInfoData) {
		bladeRedis.sAdd(CacheNames.PAYMENT + ":" + ARTIFICIAL_AUTH_LIST_KEY, authInfoData);
	}

	/***
	 * 	获取-- 人工微信认证队列
	 *
	 * @return*/
	public static Set<ArtificialAuthInfoData> artificialAuthList() {
		Set<ArtificialAuthInfoData> authList = bladeRedis.sMembers(CacheNames.PAYMENT + ":" + ARTIFICIAL_AUTH_LIST_KEY);
		return authList;
	}

	/***
	 * 	人工微信认证队列--移除成员
	 * */
	public static void removeArtificialAuthMember(ArtificialAuthInfoData... authInfoData) {
		bladeRedis.sRem(CacheNames.PAYMENT + ":" + ARTIFICIAL_AUTH_LIST_KEY, authInfoData);
	}

}
