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

import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.app.inner.service.sys.SysCountryCodeClientService;
import com.red.circle.other.inner.endpoint.sys.api.SysCountryCodeClientApi;
import com.red.circle.other.inner.model.cmd.sys.SysCountryCodeCmd;
import com.red.circle.other.inner.model.cmd.sys.SysCountryCodePageQryCmd;
import com.red.circle.other.inner.model.dto.sys.SysCountryCodeDTO;
import java.util.List;
import java.util.Map;
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 pengliang on 2023/5/24
 */
@Validated
@RestController
@RequestMapping(value = SysCountryCodeClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class SysCountryCodeClientEndpoint implements SysCountryCodeClientApi {

  private final SysCountryCodeClientService sysCountryCodeClientService;

  @Override
  public ResultResponse<SysCountryCodeDTO> getById(Long id) {
    return ResultResponse.success(sysCountryCodeClientService.getById(id));
  }

  @Override
  public ResultResponse<SysCountryCodeDTO> getByCode(String code) {
    return ResultResponse.success(sysCountryCodeClientService.getByCode(code));
  }

  @Override
  public ResultResponse<List<SysCountryCodeDTO>> listOpenCountry() {
    return ResultResponse.success(sysCountryCodeClientService.listOpenCountry());
  }

  @Override
  public ResultResponse<List<SysCountryCodeDTO>> listOpenCountryTop(Integer size) {
    return ResultResponse.success(sysCountryCodeClientService.listOpenCountryTop(size));
  }

  @Override
  public ResultResponse<Boolean> checkOpenPhonePrefix(Integer phonePrefix) {
    return ResultResponse.success(sysCountryCodeClientService.checkOpenPhonePrefix(phonePrefix));
  }

  @Override
  public ResultResponse<Map<Long, SysCountryCodeDTO>> mapByIdes(Set<Long> countryIds) {
    return ResultResponse.success(sysCountryCodeClientService.mapByIdes(countryIds));
  }

  @Override
  public ResultResponse<List<SysCountryCodeDTO>> listContent() {
    return ResultResponse.success(sysCountryCodeClientService.listContent());
  }

  @Override
  public ResultResponse<PageResult<SysCountryCodeDTO>> sysCountryCodePage(
      SysCountryCodePageQryCmd query) {
    return ResultResponse.success(sysCountryCodeClientService.sysCountryCodePage(query));
  }

  @Override
  public ResultResponse<Void> updateCountryCode(SysCountryCodeCmd cmd) {
    sysCountryCodeClientService.updateCountryCode(cmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> addCountryCode(SysCountryCodeCmd cmd) {
    sysCountryCodeClientService.addCountryCode(cmd);
    return ResultResponse.success();
  }
}
