package com.goldenwater.slgc.controller.proxy;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.slgc.config.ApiProperties;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "30. 水源地管理代理")
@RestController
@RequestMapping("/slgc/water-source")
public class WaterSourceController extends BaseController {

    private final ApiProperties apiProperties;

    public WaterSourceController(ApiProperties apiProperties) {
        this.apiProperties = apiProperties;
    }

    @Operation(summary = "30.01 根据水源地ID获取水功能区")
    @GetMapping("/getWfBySwsId")
    public AjaxResult getWfBySwsId(@RequestParam String swsId) {
        return success(ProxyHelper.fetchJson(apiProperties.getWaterSource() + "/water/source/getWfBySwsId?swsId=" + swsId));
    }

    @Operation(summary = "30.02 根据水源地ID获取水源地详情")
    @GetMapping("/getSydByswsId")
    public AjaxResult getSydByswsId(@RequestParam String swsId) {
        return success(ProxyHelper.fetchJson(apiProperties.getWaterSource() + "/water/source/getSydByswsId?swsId=" + swsId));
    }

    @Operation(summary = "30.03 获取所有水源地")
    @GetMapping("/getAllSWS")
    public AjaxResult getAllSWS(@RequestParam String type) {
        return success(ProxyHelper.fetchJson(apiProperties.getWaterSource() + "/water/source/getAllSWS?type=" + type));
    }

    @Operation(summary = "30.04 更新点位信息")
    @PostMapping("/updatePoint")
    public AjaxResult updatePoint(@RequestParam String districtId, @RequestParam String wzPoint, @RequestParam String districtSide) {
        return success(ProxyHelper.fetchJson(apiProperties.getWaterSource()
                + "/water/source/updatePoint?districtId=" + districtId + "&wzPoint=" + wzPoint + "&districtSide=" + districtSide));
    }

    @Operation(summary = "30.05 按年统计")
    @GetMapping("/sumcyear")
    public AjaxResult sumcyear(@RequestParam String swsId, @RequestParam String year) {
        return success(ProxyHelper.fetchJson(apiProperties.getWaterSource() + "/water/source/sumcyear?swsId=" + swsId + "&year=" + year));
    }

    @Operation(summary = "30.06 按类型获取区域")
    @GetMapping("/getAreaByType")
    public AjaxResult getAreaByType(@RequestParam String type, @RequestParam(required = false) String wfzId, @RequestParam(required = false) String swsId) {
        String url = apiProperties.getWaterSource() + "/water/source/getAreaByType?type=" + type;
        if (wfzId != null) url += "&wfzId=" + wfzId;
        if (swsId != null) url += "&swsId=" + swsId;
        return success(ProxyHelper.fetchJson(url));
    }

    @Operation(summary = "30.07 获取点位")
    @GetMapping("/getPoint")
    public AjaxResult getPoint(@RequestParam String qyid) {
        return success(ProxyHelper.fetchJson(apiProperties.getWaterSource() + "/water/source/getPoint?qyid=" + qyid));
    }
}
