package com.red.circle.other.adapter.app.activity;

import com.red.circle.other.app.dto.clientobject.activity.TemporaryActivityCountCO;
import com.red.circle.other.app.dto.cmd.activity.TemporaryActivityQueryCmd;
import com.red.circle.other.app.service.activity.AppTemporaryActivityService;
import com.red.circle.tool.core.date.TimestampUtils;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 临时活动
 *
 * @author lisizhe on 2023/9/25
 * @eo.api-type http
 * @eo.groupName 活动服务.临时活动
 * @eo.path /activity/temporary-activity-count
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/activity/temporary-activity-count", produces = MediaType.APPLICATION_JSON_VALUE)
public class TemporaryActivityCountRestController {

  private final AppTemporaryActivityService appTemporaryActivityService;

  /**
   * 获取排行榜.
   *
   * @eo.name 获取排行榜
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping
  public List<TemporaryActivityCountCO> listRank(@Validated TemporaryActivityQueryCmd cmd) {
    return appTemporaryActivityService.listRank(cmd);
  }

  /**
   * 获取倒计时.
   *
   * @eo.name 获取倒计时
   * @eo.url /count-down
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/count-down")
  public String countDown(Long endTime) {
    if (Objects.isNull(endTime) || endTime < 0) {
      return "0";
    }
    long countDown = endTime - TimestampUtils.now().getTime();
    return Objects.toString(countDown < 0 ? 0 : countDown);
  }

}
