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

import com.red.circle.component.redis.service.RedisService;
import com.red.circle.other.infra.database.cache.key.ActivityKeys;
import com.red.circle.other.infra.database.cache.service.other.AgentActivityCacheService;
import java.util.concurrent.TimeUnit;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 代理活动缓存服务.
 *
 * @author pengshigang on 2023/5/29
 */
@Service
@RequiredArgsConstructor
public class AgentActivityCacheServiceImpl implements AgentActivityCacheService {

  private final RedisService redisService;

  @Override
  public long getWeekCountDown() {
    return redisService
        .getExpire(ActivityKeys.AGENT_ACTIVITY_WEEK_COUNT_DOWN.name(), TimeUnit.MILLISECONDS);
  }

  @Override
  public void cacheWeekCountDown(long countDown) {
    redisService
        .setIfAbsent(ActivityKeys.AGENT_ACTIVITY_WEEK_COUNT_DOWN.name(), countDown, countDown,
            TimeUnit.MILLISECONDS);
  }

  @Override
  public long getMonthCountDown() {
    return redisService
        .getExpire(ActivityKeys.AGENT_ACTIVITY_MONTH_COUNT_DOWN.name());
  }

  @Override
  public void cacheMonthCountDown(long countDown) {
    redisService
        .setIfAbsent(ActivityKeys.AGENT_ACTIVITY_MONTH_COUNT_DOWN.name(), countDown, countDown,
            TimeUnit.MILLISECONDS);
  }

}
