package com.red.circle.other.app.command.activity.query;

import com.red.circle.component.redis.service.RedisService;
import com.red.circle.framework.core.dto.CommonCommand;
import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway;
import com.red.circle.other.infra.database.cache.key.ActivityKeys;
import com.red.circle.tool.core.text.StringUtils;
import java.util.List;
import java.util.concurrent.TimeUnit;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 房间粉丝人气票活动 - 倒计时.
 * </p>
 *
 * @author pengshigang
 * @since 2023-6-10
 */
@Component
@RequiredArgsConstructor
public class FanVotesActivityCountdownQueryExe {

  private final RedisService redisService;
  private final UserRegionGateway userRegionGateway;

  public Long execute(CommonCommand cmd) {

    String code = userRegionGateway.getRegionCode(cmd.getReqUserId());
    if (StringUtils.isBlank(code)) {
      return 0L;
    }

    if (List.of("IN", "PK", "BD").contains(code)) {
      return redisService
          .getExpire(ActivityKeys.ROOM_FAN_VOTES_ACTIVITY_IN_COUNT_DOWN.name(),
              TimeUnit.MILLISECONDS);
    }

    if ("ID".equals(code)) {
      return redisService
          .getExpire(ActivityKeys.ROOM_FAN_VOTES_ACTIVITY_ID_COUNT_DOWN.name(),
              TimeUnit.MILLISECONDS);
    }

    if ("AR".equals(code)) {
      return redisService
          .getExpire(ActivityKeys.ROOM_FAN_VOTES_ACTIVITY_AR_COUNT_DOWN.name(),
              TimeUnit.MILLISECONDS);
    }

    return 0L;
  }

}
