package com.yida.data.school.secondClass.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.school.secondClass.EduSecondClassVenue;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.school.secondClass.service.EduSecondClassVenueService;
import com.yida.data.school.vo.secondClass.VenueVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * Controller
 *
 * @author zhanghaijun
 * @date 2022-04-18 09:39:53
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/secondClass/venue")
@RequiredArgsConstructor
public class EduSecondClassVenueController {

    private final EduSecondClassVenueService eduSecondClassVenueService;

    @ApiOperation("分页查询场馆")
    @GetMapping("/listVenuePage")
    public ResultBean<IPage<VenueVO>> listVenuePage(@RequestParam(required = false) String name,
        @RequestParam(defaultValue = "1") Integer pageNum,
        @RequestParam(defaultValue = "10") Integer pageSize) {
        return ResultBean
            .buildSuccess(eduSecondClassVenueService.listVenuePage(FebsUtil.getTopDeptId(), name, pageNum, pageSize));
    }

    @ApiOperation("查询详情")
    @GetMapping("/getInfo")
    public ResultBean<VenueVO> getInfo(Long id) {
        return ResultBean.buildSuccess(eduSecondClassVenueService.getInfo(id, false));
    }

    @ApiOperation("保存场馆")
    @PostMapping("/saveVenue")
    public ResultBean saveVenue(@RequestBody EduSecondClassVenue venue) {
        venue.setDeptId(FebsUtil.getTopDeptId());
        eduSecondClassVenueService.saveVenue(venue);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("删除场馆")
    @GetMapping("/delVenue")
    public ResultBean delVenue(Long id) {
        eduSecondClassVenueService.delVenue(id);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("改变场馆状态")
    @GetMapping("/changeStatus")
    public ResultBean changeStatus(Long id, Integer status, @RequestParam(required = false) Long subjectId) {
        eduSecondClassVenueService.changeStatus(id, status, subjectId);
        return ResultBean.buildSuccess();
    }
}
