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.WeekStarCacheService;
import java.util.concurrent.TimeUnit;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 周星缓存实现.
 *
 * @author pengliang on 2021/5/18
 */
@Service
@RequiredArgsConstructor
public class WeekStarCacheServiceImpl implements WeekStarCacheService {

  private final RedisService redisService;

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

  @Override
  public void cacheCountDown(long countDown) {
    redisService
        .setString(ActivityKeys.WEEK_COUNT_DOWN.name(), countDown, countDown,
            TimeUnit.MILLISECONDS);
  }

  @Override
  public String getWeekStarStartEndDate(String key) {
    return redisService.getString(ActivityKeys.WEEK_STAR_START_END_DATE.name());
  }

  @Override
  public void setWeekStarStartEndDate(String time) {
    redisService
        .setString(ActivityKeys.WEEK_STAR_START_END_DATE.name(), time, 7, TimeUnit.DAYS);
  }


}
