package com.cool.store.controller;

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 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
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),
            @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));
    }



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