package com.yx.face.controller.admin;

import com.yx.face.boot.core.BaseController;
import com.yx.face.boot.restful.RestResponse;
import com.yx.face.boot.restful.RestResult;
import com.yx.face.model.vo.AreaCodeVOList;
import com.yx.face.service.AreaCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "C 地址编码表管理 API")
@RestController
@RequestMapping("admin/areaCode")
public class AreaCodeController extends BaseController {

    /**
     * 服务对象
     */
    private final AreaCodeService areaCodeService;


    @ApiOperation("获取省级列表")
    @GetMapping("getProvince")
    public RestResult<List<AreaCodeVOList>> doGetInfo() {
        return RestResponse.ok(areaCodeService.getProvince());
    }
    @ApiOperation("获取城市列表")
    @GetMapping("getCity")
    public RestResult<List<AreaCodeVOList>> getCity(@ApiParam(name = "areaCodeId", value = "省份的id值" ,required = true)Integer areaCodeId) {
        if (areaCodeId==null){
            return RestResponse.error("省份的主键值不能为空");
        }
        return RestResponse.ok(areaCodeService.getCity(areaCodeId));
    }
    @ApiOperation("获取县区列表")
    @GetMapping("getArea")
    public RestResult<List<AreaCodeVOList>> getArea(@ApiParam(name = "areaCodeId", value = "市级的id值",required = true)Integer areaCodeId) {
        if (areaCodeId==null){
            return RestResponse.error("城市的主键值不能为空");
        }
        return RestResponse.ok(areaCodeService.getArea(areaCodeId));
    }
    @ApiOperation("获取街道乡镇列表")
    @GetMapping("getStreet")
    public RestResult<List<AreaCodeVOList>> getStreet(@ApiParam(name = "areaCodeId", value = "县区的id值",required = true)Integer areaCodeId) {
        if (areaCodeId==null){
            return RestResponse.error("县区的主键值不能为空");
        }
        return RestResponse.ok(areaCodeService.getStreet(areaCodeId));
    }

}
