package com.gree.mall.manager.controller.common;

import com.gree.mall.manager.bean.common.RegionBean;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.common.LbsAmapLogic;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;

@RequiredArgsConstructor
@Slf4j
@RestController
@Api(value = "高德地图API", tags ={"高德地图API"} )
@RequestMapping("lbs/amap")
public class LbsAmapController {

    private final LbsAmapLogic lbsAmapLogic;


    @PostMapping("region/query")
    @ApiOperation(value = "根据经纬度反查省市区街道")
    public ResponseHelper<RegionBean> detailRange(
            @ApiParam(value = "经度", required = true) @RequestParam String lng,
            @ApiParam(value = "纬度", required = true) @RequestParam String lat
    ) {
        RegionBean regionBean = lbsAmapLogic.getRegionByLngLat(lng + "," + lat);
        //        String street = regionByLngLat.get("street");
        //        String province = regionByLngLat.get("province");
        //        String city = regionByLngLat.get("city");
        //        String area = regionByLngLat.get("area");
        //        LbsAmap lbsAmap = lbsLogic.getByRegion(province, city, area, street);
        return ResponseHelper.success(regionBean);
    }


    @PostMapping("region/query2")
    @ApiOperation(value = "根据中文地址反查经纬度省市区街道")
    public ResponseHelper<RegionBean> queryRegion(@ApiParam(value = "中文地址(越详细越好)", required = true) @RequestParam String address) {
        String lnglat = lbsAmapLogic.getLocationByAddress(address);
        RegionBean regionBean = lbsAmapLogic.getRegionByLngLat(lnglat);
        return ResponseHelper.success(regionBean);
    }



}
