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

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway;
import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils;
import com.red.circle.tool.core.text.StringUtils;
import java.time.ZonedDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 房间粉丝人气票活动 - 开始状态.
 * </p>
 *
 * @author pengshigang
 * @since 2023-6-10
 */
@Component
@RequiredArgsConstructor
public class FanVotesActivityStatusQueryExe {

  private final UserRegionGateway userRegionGateway;

  public Boolean execute(AppExtCommand cmd) {

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

    // 基于当前沙特时间计算
    ZonedDateTime nowTime = ZonedDateTimeAsiaRiyadhUtils.now();
    int hour = nowTime.getHour();
    int minute = nowTime.getMinute();

    // 印度，孟加拉，巴基斯坦 = 北京时间 23:30-0:30 => 沙特时间 18:30-19:30
    if (List.of("IN", "PK", "BD").contains(code) && ((hour == 18 && minute >= 30) || (hour == 19
        && minute <= 30))) {
      return Boolean.TRUE;
    }

    // 印尼 = 北京时间 20:30-21:30 => 沙特时间 15:30-16:30
    if ("ID".equals(code) && ((hour == 15 && minute >= 30) || (hour == 16 && minute <= 30))) {
      return Boolean.TRUE;
    }

    // 阿拉伯 = 北京时间 2:30-3:30 => 沙特时间 21:30-22:30
    if ("AR".equals(code) && ((hour == 21 && minute >= 30) || (hour == 22 && minute <= 30))) {
      return Boolean.TRUE;
    }

    return Boolean.FALSE;
  }

}
