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

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.component.redis.service.RedisService;
import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.framework.core.response.CommonErrorCode;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.app.dto.cmd.qibla.PrayCmd;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 祈祷App临时接口
 *
 * @author zongpubin on 2023/11/22
 */
@Deprecated
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/pray", produces = MediaType.APPLICATION_JSON_VALUE)
public class PrayRestController extends BaseController {


  private final RedisService redisService;
  private final String PRAY_KEY = "PRAY";

  /**
   * 上麦
   */
  @PostMapping
  public void mike(@RequestBody @Validated PrayCmd cmd) {
    ResponseAssert.isNull(CommonErrorCode.SUBMIT_FAIL, redisService.hashGet(PRAY_KEY,
        getKey(cmd.getSort())));

    redisService.hashPut(PRAY_KEY, getKey(cmd.getSort()), cmd.getSort());
  }

  /**
   * 下麦
   */
  @PostMapping("/below")
  public void belowMike(@RequestBody @Validated PrayCmd cmd) {
    redisService.hashDelete(PRAY_KEY, getKey(cmd.getSort()));
  }

  /**
   * 麦位列表
   */
  @GetMapping("/list")
  public Set<String> listMike(AppExtCommand cmd) {
    return redisService.hashKeys(PRAY_KEY);
  }


  private String getKey(String sort) {
    return "MIKE_INFO:" + sort;
  }

}
