package cn.reghao.tnb.content.app.geo.controller;

import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.content.app.geo.model.vo.ChartMap;
import cn.reghao.tnb.common.db.SelectOption;
import cn.reghao.tnb.content.app.geo.service.ChartMapService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.MediaType;
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;

/**
 * @author reghao
 * @date 2025-08-19 15:59:13
 */
@Tag(name = "数据地图接口")
@RestController
@RequestMapping("/api/geo/chartmap")
public class ChartMapController {
    private final ChartMapService chartMapService;

    public ChartMapController(ChartMapService chartMapService) {
        this.chartMapService = chartMapService;
    }

    @GetMapping(value = "/area", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getGeoJsonList() {
        List<SelectOption> selectOptionList = chartMapService.getAreaNameValue();
        return WebResult.success(selectOptionList);
    }

    @GetMapping(value = "/geojson", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getGeoJson(@RequestParam("areaCode") String areaCodeStr) {
        String[] arr = areaCodeStr.split("-");
        int areaCode = Integer.parseInt(arr[0]);
        int deep = Integer.parseInt(arr[1]);
        ChartMap chartMap = chartMapService.getChartMap(areaCode, deep);
        return WebResult.success(chartMap);
    }
}
