package com.cool.store.controller.webb;

import com.cool.store.common.PageBasicInfo;
import com.cool.store.context.CurrentUserHolder;
import com.cool.store.request.OpenAreaRequest;
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.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

/**
 * @Author suzhuhong
 * @Date 2023/6/15 9:49
 * @Version 1.0
 */
@RestController
@RequestMapping("pc/openArea")
@Api(tags = "PC开放城市")
public class OpenAreaController {

    @Resource
    OpenAreaService openAreaService;

    @GetMapping(path = "/getOpenAreaTree")
    @ApiOperation("开放城市树-搜索城市 到第二节点")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "搜索关键字", required = false),
            @ApiImplicitParam(name = "areaStatus", value = "状态 open-开放 keyOpen-重点开放 notOpen-未开放 saturated-已饱和", required = false)
    })
    public ResponseResult<List<OpenAreaTreeVO>> getOpenAreaTree(@RequestParam(value = "keyword",required = false)String keyword,
                                                                @RequestParam(value = "areaStatus",required = false)String areaStatus){
        return  ResponseResult.success(openAreaService.queryByKeyword(keyword,areaStatus,Boolean.TRUE));
    }


    @GetMapping(path = "/getAllOpenAreaTree")
    @ApiOperation("开放城市树-所有节点")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "搜索关键字", required = false)
    })
    public ResponseResult<List<OpenAreaTreeVO>> getAllOpenAreaTree(@RequestParam(value = "keyword",required = false)String keyword){
        return  ResponseResult.success(openAreaService.queryAllOpenAreaByKeyword(keyword,null,Boolean.FALSE));
    }


    @GetMapping(path = "/getOpenAreaList")
    @ApiOperation("开放城市树-子列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "父区域名称", required = false)
    })
    public ResponseResult<List<OpenAreaVO>> getOpenAreaList(@RequestParam(value = "parentId",required = false)Long parentId){
        return  ResponseResult.success(openAreaService.getChildrenList(parentId));
    }

    @PostMapping(path = "/changeOpenAreaStatus")
    @ApiOperation("变更开放区域状态")
    public ResponseResult<Boolean> changeOpenAreaStatus(@RequestBody OpenAreaRequest openAreaRequest){
        String userId = CurrentUserHolder.getUserId();
        return ResponseResult.success(openAreaService.batchUpdate( userId, openAreaRequest));
    }


    @GetMapping(path = "/getKeyOpenAreaList")
    @ApiOperation("重点城市列表")
    public ResponseResult<PageInfo<OpenAreaVO>> getKeyOpenAreaList(@RequestParam(value = "pageNumber",required = true,defaultValue = "1")Integer pageNumber,
                                                                   @RequestParam(value = "pageSize",required = true,defaultValue = "10")Integer pageSize,
                                                                   @RequestParam(value = "keyword",required = false)String keyword,
                                                                   @RequestParam(value = "status",required = false)Integer status ){
        return ResponseResult.success(openAreaService.queryKeyOpenAreaList(pageSize,pageNumber,keyword,status));
    }

    @GetMapping(path = "/updateKeyCityStatus")
    @ApiOperation("启用或者禁用重点城市")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "区域ID", required = true),
            @ApiImplicitParam(name = "keyOpenStatus", value = "启用或者禁用 启用-0 禁用-1", required = true)
    })
    public ResponseResult<Boolean> getKeyOpenAreaList(@RequestParam(value = "id",required = false)Long id,
                                                      @RequestParam(value = "keyOpenStatus",required = false)Integer keyOpenStatus ){
        return ResponseResult.success(openAreaService.updateKeyCityStatus(id,keyOpenStatus));
    }


    @GetMapping(path = "/deleteKeyCity")
    @ApiOperation("删除重点城市")
    public ResponseResult<Boolean> getKeyOpenAreaList(@RequestParam(value = "id",required = false)Long id){
        return ResponseResult.success(openAreaService.deleteKeyCity(id));
    }

}
