package com.zbkj.admin.controller;

import com.zbkj.common.model.place.PlaceRegister;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.*;
import com.zbkj.common.response.CommonResult;
import com.zbkj.common.vo.PlaceRegisterVo;
import com.zbkj.service.service.PlaceRegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping("api/admin/place")
@Api(tags = "场地预约")
public class PlaceRegisterController {

    @Autowired
    private PlaceRegisterService placeRegisterService;

    @PreAuthorize("hasAuthority('admin:place:list')")
    @ApiOperation(value = "分页列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<PlaceRegisterVo>> getList(@Validated PlaceRegisterSearchRequest request,
                                                             @Validated PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(placeRegisterService.getAdminList(request, pageParamRequest)));
    }

    /**
     * 删除
     * @param id Integer
     */
    @PreAuthorize("hasAuthority('admin:activity:delete')")
    @ApiOperation(value = "删除参与记录")
    @RequestMapping(value = "/records/delete", method = RequestMethod.GET)
    @ApiImplicitParam(name="id", value="记录ID")
    public CommonResult<String> recordsDelete(@RequestParam(value = "id") Integer id) {
        if (placeRegisterService.recordsDelete(id)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 修改
     * @param id integer id
     * @param request 修改参数
     */
    @PreAuthorize("hasAuthority('admin:place:update')")
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ApiImplicitParam(name="id", value="预约ID")
    public CommonResult<String> updateRegister(@RequestParam Integer id, @RequestBody @Validated PlaceRegisterRequest request) {
        if (placeRegisterService.updateRegister(id, request)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 查询
     * @param id Integer
     */
    @PreAuthorize("hasAuthority('admin:place:info')")
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @ApiImplicitParam(name="id", value="预约ID")
    public CommonResult<PlaceRegister> info(@RequestParam(value = "id") Integer id) {
        return CommonResult.success(placeRegisterService.getDetail(id));
    }
}



