package com.bonus.material.project.controller;

import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.project.service.RegionService;
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 javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 地区信息
 *
 * @author 30791
 * @version 1.0
 * Create by 2025/11/13 22:05
 */

@RestController
@RequestMapping("/region")
public class RegionController {

    @Resource
    private RegionService regionService;


    // 获取所有省份（无变化）
    @GetMapping("/provinces")
    public AjaxResult getProvinces() {
        List<Map<String, Object>> provinces = regionService.getProvinces();
        return AjaxResult.success(provinces);
    }

    // 根据「省的area_code」获取城市（参数名改为provinceAreaCode）
    @GetMapping("/cities")
    public AjaxResult getCities(@RequestParam String provinceAreaCode) {
        List<Map<String, Object>> cities = regionService.getCitiesByProvinceAreaCode(provinceAreaCode);
        return AjaxResult.success(cities);
    }

    // 根据「市的area_code」获取区县（参数名改为cityAreaCode）
    @GetMapping("/counties")
    public AjaxResult getCounties(@RequestParam String cityAreaCode) {
        List<Map<String, Object>> counties = regionService.getDistrictsByCityAreaCode(cityAreaCode);
        return AjaxResult.success(counties);
    }
}
