package com.red.circle.other.app.inner.endpoint.user.user;

import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.app.inner.service.user.user.RequestBlacklistClientService;
import com.red.circle.other.inner.endpoint.user.user.api.RequestBlacklistClientApi;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 请求黑名单.
 *
 * @author lisizhe on 2023/8/18
 */
@Validated
@RestController
@RequestMapping(value = RequestBlacklistClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class RequestBlacklistClientEndpoint implements RequestBlacklistClientApi {

  private final RequestBlacklistClientService requestBlacklistService;

  @Override
  public ResultResponse<Void> addIp(String ip) {
    requestBlacklistService.addIp(ip);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> addPhoneModel(String phoneModel) {
    requestBlacklistService.addPhoneModel(phoneModel);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> delKey(String key) {
    requestBlacklistService.delKey(key);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Boolean> matchIpOrPhoneModel(String ip, String phoneModel) {
    return ResultResponse.success(requestBlacklistService.matchIpOrPhoneModel(ip, phoneModel));
  }

  @Override
  public ResultResponse<Set<String>> getKeys() {
    return ResultResponse.success(requestBlacklistService.getKeys());
  }
}
