package com.codvision.base.controller.manager;

import com.codvision.base.entity.Region;
import com.codvision.base.entity.vo.RegionVO;
import com.codvision.base.service.IRegionService;
import com.codvision.commoncore.common.ResponseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 行政区域 管理模块
 *
 * @author zz
 * @date 2023-08-09
 */
@RestController
@RequestMapping("/v1/manager/region" )
@Api(tags = "地址信息接口" )
public class ManagerRegionController {

    @Autowired
    private IRegionService regionService;

    @ApiOperation(value = "点地图获取地址信息" )
    @GetMapping(value = "/region" )
    public ResponseEntity<Map<String, Object>> getRegion(@ApiParam(value = "城市code" , required = true) @RequestParam String cityCode, @ApiParam(value = "镇名称" , required = true) @RequestParam String townName) {
        return new ResponseEntity().data(regionService.getRegion(cityCode, townName));
    }

    @GetMapping(value = "/name" )
    @ApiOperation(value = "根据名字获取地区地址id" )
    public ResponseEntity<String> getItemByLastName(String lastName) {
        return new ResponseEntity().data(regionService.getItemByLastName(lastName));
    }

    @GetMapping(value = "/item/getItem" )
    @ApiOperation(value = "通过id获取子地区" )
    public ResponseEntity<List<Region>> getItem(@ApiParam(value = "地区ID" , required = true) @RequestParam Long id) {
        return new ResponseEntity().data(regionService.getItem(id));
    }

    @GetMapping(value = "/allCity" )
    @ApiOperation(value = "获取所有的省-市" )
    public ResponseEntity<List<RegionVO>> getAllCity() {
        return new ResponseEntity().data(regionService.getAllCity());
    }

}
