package com.cool.store.controller;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.request.IntentAreaSettingRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.ZoneService;
import com.cool.store.vo.ZoneCheckVO;
import com.cool.store.vo.ZoneVO;
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/6/14 11:40
 * @Version 1.0
 */
@RestController
@Slf4j
@Api(tags = "战区")
public class ZoneController {

    @Resource
    ZoneService zoneService;

    @PostMapping(path = "/addZone")
    @ApiOperation("新建意向战区/开发战区")
    public ResponseResult<Boolean> addZone(@RequestBody IntentAreaSettingRequest intentAreaSettingRequest){
        return ResponseResult.success(zoneService.addZone( CurrentUserHolder.getUserId(),intentAreaSettingRequest));
    }

    @PostMapping(path = "/checkZone")
    @ApiOperation("校验战区")
    public ResponseResult<List<ZoneCheckVO>> checkZone(@RequestBody IntentAreaSettingRequest intentAreaSettingRequest){
        return ResponseResult.success(zoneService.checkZone(intentAreaSettingRequest));
    }

    @PostMapping(path = "/updateZone")
    @ApiOperation("编辑意向战区/开发战区")
    public ResponseResult<Boolean> updateZone(@RequestBody IntentAreaSettingRequest intentAreaSettingRequest){

        return ResponseResult.success(zoneService.updateZone(CurrentUserHolder.getUserId(),intentAreaSettingRequest));
    }

    @GetMapping(path = "/getZoneList")
    @ApiOperation("战区列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "意向区域-intent  开发区域=dev", required = false),
    })
    public ResponseResult<PageInfo<ZoneVO>> getZoneList(@RequestParam(value = "type",required = false)String type,
                                                        @RequestParam(value = "pageNumber",required = false,defaultValue = "1")Integer pageNumber,
                                                        @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize){
        return  ResponseResult.success(zoneService.getZoneList(type,pageSize,pageNumber));
    }


    @GetMapping(path = "/deletedZone")
    @ApiOperation("删除战区")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = false),
    })
    public ResponseResult<Boolean> deletedZone(@RequestParam(value = "id",required = false)Long id){
        return  ResponseResult.success(zoneService.deletedZone(id));
    }

    @GetMapping(path = "/zoneDetail")
    @ApiOperation("战区详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = false),
    })
    public ResponseResult<ZoneVO> zoneDetail(@RequestParam(value = "id",required = false)Long id){
        return  ResponseResult.success(zoneService.zoneDetail(id));
    }
}
