package com.cool.store.controller.webc;

import com.cool.store.response.ResponseResult;
import com.cool.store.service.OpenAreaService;
import com.cool.store.utils.poi.constant.Constants;
import com.cool.store.vo.OpenAreaTreeVO;
import com.cool.store.vo.OpenAreaVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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;

/**
 * @Author suzhuhong
 * @Date 2024/3/13 14:37
 * @Version 1.0
 */
@RestController
@RequestMapping({"/mini/openArea" })
@Slf4j
@Api(tags = "小程序开发区域城市")
public class MiniOpenAreaController {
    @Resource
    OpenAreaService openAreaService;


    @GetMapping(path = "/getOpenAreaList")
    @ApiOperation("点击重点城市 子列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "父区域ID", required = false),
    })
    public ResponseResult<List<OpenAreaVO>> getOpenAreaList(@RequestParam(value = "parentId",required = false)Long parentId){

        return  ResponseResult.success(openAreaService.getChildrenList(parentId));
    }

    @GetMapping(path = "/areaApplyQuery")
    @ApiOperation("区域申请搜索 树形结构")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "搜索关键字", required = false)
    })
    public ResponseResult<List<OpenAreaTreeVO>> getOpenAreaList(@RequestParam(value = "keyword",required = false)String keyword){
        List<OpenAreaTreeVO>  openAreaTreeVOS = openAreaService.searchOpenArea(keyword,null,Boolean.FALSE);
        return  ResponseResult.success(openAreaTreeVOS);
    }


    @GetMapping(path = "/getKeyOpenAreaList")
    @ApiOperation("重点开放城市列表)")
    public ResponseResult<PageInfo<OpenAreaVO>> getOpenAreaList(@RequestParam(value = "pageNumber",required = false,defaultValue = "1")Integer pageNumber,
                                                                @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize){
        PageInfo<OpenAreaVO> openAreaVOPageInfo = openAreaService.queryKeyOpenAreaList(pageSize, pageNumber,null, Constants.ZERO_INTEGER);
        return  ResponseResult.success(openAreaVOPageInfo);
    }

    @GetMapping(path = "/franchisableProvinces")
    @ApiOperation("可申请省份)")
    public ResponseResult<PageInfo<OpenAreaVO>> franchisableProvinces(@RequestParam(value = "pageNumber",required = false,defaultValue = "1")Integer pageNumber,
                                                                @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize){
        PageInfo<OpenAreaVO> openAreaVOPageInfo = openAreaService.franchisableProvinces(pageSize, pageNumber);
        return  ResponseResult.success(openAreaVOPageInfo);
    }




}
