package com.red.circle.other.infra.database.cache.service.user.impl;

import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.component.redis.service.RedisService;
import com.red.circle.other.infra.database.cache.key.user.UserInviteKey;
import com.red.circle.other.infra.database.cache.service.user.UserInviteCacheService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 用户邀请 实现.
 *
 * @author pengshigang on 2022/5/23.
 */
@Service
@RequiredArgsConstructor
public class UserInviteCacheServiceImpl implements UserInviteCacheService {

  private final RedisService redisService;

  @Override
  public Double getCommissionRate(SysOriginPlatformEnum sysOrigin) {
    String val = redisService
        .getString(UserInviteKey.INVITE_USER_COMMISSION_RATIO.getKey(sysOrigin.name()));
    return StringUtils.isBlank(val) ? null : Double.valueOf(val);
  }

  @Override
  public void setCommissionRate(SysOriginPlatformEnum sysOrigin, Double proportion) {
    redisService
        .setString(UserInviteKey.INVITE_USER_COMMISSION_RATIO.getKey(sysOrigin.name()), proportion);
  }

  @Override
  public Integer getCommissionDays(SysOriginPlatformEnum sysOrigin) {
    return redisService
        .getStringToInteger(UserInviteKey.INVITE_USER_COMMISSION_DAYS.getKey(sysOrigin.name()));
  }

  @Override
  public void setCommissionDays(SysOriginPlatformEnum sysOrigin, Integer days) {
    redisService
        .setString(UserInviteKey.INVITE_USER_COMMISSION_DAYS.getKey(sysOrigin.name()), days);
  }

  @Override
  public String getRewardsReceivedRuleIds(Long userId) {
    return redisService
        .getString(UserInviteKey.INVITE_USER_REWARD_RECEIVED_LIST.getKey(userId));
  }

  @Override
  public void setRewardsReceivedRuleIds(Long userId, String list) {
    redisService
        .setString(UserInviteKey.INVITE_USER_REWARD_RECEIVED_LIST.getKey(userId), list);
  }

}
