package com.cool.store.controller;

import com.cool.store.response.ResponseResult;
import com.cool.store.service.OpenAreaService;
import com.cool.store.vo.OpenAreaTreeVO;
import com.cool.store.vo.OpenAreaVO;
import com.cool.store.vo.OpenProvinceVO;
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.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author suzhuhong
 * @Date 2023/5/29 14:19
 * @Version 1.0
 */
@RestController
@RequestMapping({"/v1/partnerManage/openArea" })
@Slf4j
@Api(tags = "小程序开发区域城市")
public class OpenAreaController {


    @Resource
    OpenAreaService openAreaService;


    @GetMapping(path = "/getOpenAreaList")
    @ApiOperation("点击重点城市/可申请加盟省份/可预约加盟省份 子列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "父区域ID", required = false),
            @ApiImplicitParam(name = "type", value = "可预约-reservation  可申请-apply ", required = false)
    })
    public ResponseResult<List<OpenAreaVO>> getOpenAreaList(@RequestParam(value = "parentId",required = false)Long parentId,
                                                            @RequestParam(value = "type",required = false)String type){

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


    @GetMapping(path = "/areaApplyQuery")
    @ApiOperation("区域申请搜索 树形结构")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "搜索关键字", required = false),
            @ApiImplicitParam(name = "applyFlag", value = "可申请标识", required = false)
    })
    public ResponseResult<List<OpenAreaTreeVO>> getOpenAreaList(@RequestParam(value = "keyword",required = false)String keyword,
                                                                @RequestParam(value = "applyFlag",required = false)Boolean applyFlag){
        List<OpenAreaTreeVO>  openAreaTreeVOS = openAreaService.searchOpenArea(keyword,applyFlag,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);
        return  ResponseResult.success(openAreaVOPageInfo);
    }



    @GetMapping(path = "/getOpenProvince")
    @ApiOperation("可申请加盟省份/可预约加盟省份")
    public ResponseResult<OpenProvinceVO> getOpenProvince(){
        return  ResponseResult.success(openAreaService.getOpenProvince());
    }






}
