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

import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.inner.model.cmd.user.SysRegionRelationCmd;
import com.red.circle.other.inner.model.cmd.user.SysRegionRelationQryCmd;
import com.red.circle.other.inner.model.dto.user.reigon.RegionRelationDTO;
import com.red.circle.other.inner.enums.user.RegionRelationGroupEnum;
import com.red.circle.other.app.inner.service.user.region.RegionRelationClientService;
import com.red.circle.other.inner.endpoint.user.region.api.RegionRelationClientApi;
import java.util.List;
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/8/20
 */
@Validated
@RestController
@RequestMapping(value = RegionRelationClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class RegionRelationClientEndpoint implements RegionRelationClientApi {

  private final RegionRelationClientService regionRelationClientService;

  @Override
  public ResultResponse<List<RegionRelationDTO>> listByRegionId(String regionId, String sysOrigin,
      RegionRelationGroupEnum group) {
    return ResultResponse.success(
        regionRelationClientService.listByRegionId(regionId, sysOrigin, group));
  }

  @Override
  public ResultResponse<PageResult<RegionRelationDTO>> pageRelation(SysRegionRelationQryCmd query) {
    return ResultResponse.success(regionRelationClientService.pageRelation(query));
  }

  @Override
  public ResultResponse<Void> add(SysRegionRelationCmd param) {
    regionRelationClientService.add(param);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> update(SysRegionRelationCmd param) {
    regionRelationClientService.update(param);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Set<Long>> getRelationIdsByRegionId(String regionId, String name) {
    return ResultResponse.success(
        regionRelationClientService.getRelationIdsByRegionId(regionId, name));
  }

}
