package com.red.circle.console.adapter.app.sys;

import com.red.circle.console.app.service.app.sys.RequestBlacklistService;
import com.red.circle.console.infra.annotations.OpsOperationReqLog;
import com.red.circle.framework.web.controller.BaseController;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 请求黑名单.
 *
 * @author pengliang on 2022/3/22
 */
@RestController
@RequestMapping("/request-black-list")
@RequiredArgsConstructor
public class RequestBlacklistResetController extends BaseController {

  private final RequestBlacklistService requestBlacklistService;

  @OpsOperationReqLog(value = "添加黑名单-IP")
  @PostMapping("/ip")
  public void addBlacklistIp(@RequestParam String ip) {
    requestBlacklistService.addIp(ip);
  }

  @OpsOperationReqLog(value = "添加黑名单-手机型号")
  @PostMapping("/phone-model")
  public void addBlacklistPhoneModel(@RequestParam String phoneModel) {
    requestBlacklistService.addPhoneModel(phoneModel);
  }

  @OpsOperationReqLog(value = "删除黑名单")
  @DeleteMapping("/del")
  public void deleteBlacklist(@RequestParam String content) {
    requestBlacklistService.delKey(content);
  }

  /**
   * 黑名单列表
   */
  @GetMapping
  public Set<String> getBlacklist() {
    return requestBlacklistService.getKeys();
  }

}
