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

import com.red.circle.component.redis.service.RedisService;
import com.red.circle.live.infra.database.cache.key.LiveUserAgoraKey;
import com.red.circle.live.infra.database.cache.service.LiveRoomCacheService;
import com.red.circle.live.infra.database.cache.service.UserAgoraTokenCacheService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * UserAgoraToken缓存服务.
 *
 * @author lixiaofei on 2024/9/4
 */
@Service
@RequiredArgsConstructor
public class LiveRoomCacheServiceImpl implements LiveRoomCacheService {

  private final RedisService redisService;
  private static final long CACHE_TIME = 3600;

  @Override
  public void remove(Long roomId) {
    redisService.delete(getRoomAccountKey(roomId));
  }

  @Override
  public void save(String roomAccount, Long roomId) {
    redisService.setIfAbsent(getRoomAccountKey(roomId), roomAccount);
  }

  @Override
  public String getRoomAccount(Long roomId) {
    return redisService.getString(getRoomAccountKey(roomId));
  }

  private String getRoomAccountKey(Long roomId) {
    return LiveUserAgoraKey.ROOM_ACCOUNT.getKey(roomId);
  }

}
