package com.tashow.cloud.system.controller.app.ip;

import static com.tashow.cloud.common.pojo.CommonResult.success;

import cn.hutool.core.lang.Assert;
import com.tashow.cloud.common.core.Area;
import com.tashow.cloud.common.pojo.CommonResult;
import com.tashow.cloud.common.util.ip.AreaUtils;
import com.tashow.cloud.common.util.object.BeanUtils;
import com.tashow.cloud.system.controller.app.ip.vo.AppAreaNodeRespVO;
import jakarta.annotation.security.PermitAll;
import java.util.List;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/** 用户 App - 地区 */
@RestController
@RequestMapping("/system/area")
@Validated
public class AppAreaController {

  /** 获得地区树 */
  @GetMapping("/tree")
  @PermitAll
  public CommonResult<List<AppAreaNodeRespVO>> getAreaTree() {
    Area area = AreaUtils.getArea(Area.ID_CHINA);
    Assert.notNull(area, "获取不到中国");
    return success(BeanUtils.toBean(area.getChildren(), AppAreaNodeRespVO.class));
  }
}
