package shop.alien.storeplatform.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.vo.StoreDictionaryVo;
import shop.alien.storeplatform.service.BaseDataService;

import java.util.List;

/**
 * web端基础数据管理 前端控制器
 *
 * @author ssk
 * @since 2025-01-xx
 */
@Slf4j
@Api(tags = {"web端基础数据管理"})
@ApiSort(3)
@CrossOrigin
@RestController
@RequestMapping("/baseData")
@RequiredArgsConstructor
public class BaseDataController {

    private final BaseDataService baseDataService;

    @ApiOperation("根据关键词获取地址提示")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "addressName", value = "地址关键词", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "city", value = "城市", dataType = "String", paramType = "query", required = false)
    })
    @GetMapping("/getAddressPrompt")
    public R<JSONObject> getAddressPrompt(@RequestParam(value = "addressName") String addressName,
                                           @RequestParam(value = "city", required = false) String city) {
        log.info("BaseDataController.getAddressPrompt?addressName={}&city={}", addressName, city);
        return baseDataService.getAddressPrompt(addressName, city);
    }

    @ApiOperation("获取行政区划数据")
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adCode", value = "行政区划代码(100000:国家, 省代码:省, 市代码:市)", dataType = "String", paramType = "query", required = false, defaultValue = "100000", example = "100000")
    })
    @GetMapping("/getDistrict")
    public R<JSONObject> getDistrict(@RequestParam(value = "adCode", required = false, defaultValue = "100000") String adCode) {
        log.info("BaseDataController.getDistrict?adCode={}", adCode);
        return baseDataService.getDistrict(adCode);
    }

    @ApiOperation("获取经营板块基础数据")
    @ApiOperationSupport(order = 3)
    @GetMapping("/getBusinessSection")
    public R<List<StoreDictionaryVo>> getBusinessSection() {
        log.info("BaseDataController.getBusinessSection");
        return baseDataService.getBusinessSection();
    }

    @ApiOperation("获取经营种类基础数据")
    @ApiOperationSupport(order = 4)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "经营板块ID", dataType = "String", paramType = "query", required = true, example = "1")
    })
    @GetMapping("/getBusinessTypes")
    public R<List<StoreDictionaryVo>> getBusinessTypes(@RequestParam("parentId") String parentId) {
        log.info("BaseDataController.getBusinessTypes?parentId={}", parentId);
        return baseDataService.getBusinessTypes(parentId);
    }
}



