package com.yida.data.device.camera.controller.web;

import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.device.camera.service.EduCameraAuthorityTeacherService;
import com.yida.data.device.camera.service.EduCameraStrategyThemeService;
import com.yida.data.device.dto.camera.ThemeSaveDTO;
import com.yida.data.device.vo.camera.AuthorityByGroupIdVO;
import com.yida.data.device.vo.camera.ThemeListVO;
import com.yida.data.device.vo.camera.ThemeTagVO;
import com.yida.data.device.vo.camera.ThemeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ccl
 */
@Api(tags = "监控-主题配置和教师权限")
@Slf4j
@Validated
@RestController
@RequestMapping("/camera/set")
@RequiredArgsConstructor
public class WebEduCameraSetController {

    private final EduCameraStrategyThemeService themeService;
    private final EduCameraAuthorityTeacherService authorityTeacherService;

    @ApiOperation("查询主题标签列表")
    @GetMapping("/listThemeTag")
    public ResultBean<List<ThemeTagVO>> listThemeTag() {
        return ResultBean.buildSuccess(themeService.listThemeTag(FebsUtil.getDeptId()));
    }

    @ApiOperation("查询主题详情")
    @GetMapping("/getThemeInfo")
    public ResultBean<ThemeVO> getThemeInfo(
            @ApiParam(value = "主题id", required = true) @RequestParam Integer themeId) {
        return ResultBean.buildSuccess(themeService.getThemeInfo(themeId));
    }

    @ApiOperation("新增或者修改主题")
    @PostMapping("/saveOrUpdateTheme")
    public ResultBean<Long> saveOrUpdateTheme(@RequestBody ThemeSaveDTO dto) {
        return ResultBean.buildSuccess(themeService.saveOrUpdateTheme(FebsUtil.getDeptId(), dto));
    }

    @ApiOperation("删除主题")
    @GetMapping("/deleteTheme")
    public ResultBean<String> deleteTheme(
            @ApiParam(value = "主题id", required = true) @RequestParam Integer themeId) {
        themeService.deleteTheme(themeId);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("查询主题列表")
    @GetMapping("/listTheme")
    public ResultBean<List<ThemeListVO>> listTheme() {
        return ResultBean.buildSuccess(themeService.listTheme(FebsUtil.getDeptId()));
    }

    @ApiOperation("查询区域组对应权限")
    @GetMapping("/findAuthorityByGroupId")
    public ResultBean<List<AuthorityByGroupIdVO>> findAuthorityByGroupId(@RequestParam Long groupId) {

        return ResultBean.buildSuccess(authorityTeacherService.findAuthorityByGroupId(groupId));
    }

    @ApiOperation("系新增区域组对应权限")
    @PostMapping("/saveAuthority")
    public ResultBean saveAuthority(@RequestBody List<AuthorityByGroupIdVO> vos) {
        authorityTeacherService.saveAuthority(vos);
        return ResultBean.buildSuccess();
    }
}
