package com.usky.meeting.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.meeting.domain.MeetingDevice;
import com.usky.meeting.service.MeetingDeviceService;
import com.usky.meeting.service.vo.MeetingDeviceBindFacePersonQueryVO;
import com.usky.meeting.service.vo.MeetingDeviceBindFacePersonVO;
import com.usky.meeting.service.vo.MeetingDeviceBindPersonRequest;
import com.usky.meeting.service.vo.MeetingDeviceRequestVO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 设备表 前端控制器
 * </p>
 *
 * @author zyj
 * @since 2024-03-08
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/meetingDevice")
public class MeetingDeviceController {

    @Autowired
    private MeetingDeviceService meetingDeviceService;

    /**
     * 设备列表
     * @param requestVO
     * @return
     */
    @PostMapping("meetingDeviceList")
    public ApiResult<CommonPage<MeetingDevice>> meetingDeviceList(@RequestBody MeetingDeviceRequestVO requestVO){
        return ApiResult.success(meetingDeviceService.meetingDeviceList(requestVO));
    }

    /**
     * 分页查询设备已绑定人员（可通过 deviceCode 过滤）
     */
    @PostMapping("/bindFacePerson/page")
    public ApiResult<CommonPage<MeetingDeviceBindFacePersonVO>> pageBindFacePersons(
            @RequestBody MeetingDeviceBindFacePersonQueryVO queryVO) {
        return ApiResult.success(meetingDeviceService.pageBindFacePersons(queryVO));
    }

    /**
     * 新增
     * @param meetingDevice
     * @return
     */
    @Log(title = "新增-会议屏设备", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult<Void> add(@RequestBody MeetingDevice meetingDevice){
        meetingDeviceService.add(meetingDevice);
        return ApiResult.success();
    }

    /**
     * 修改
     * @param meetingDevice
     * @return
     */
    @Log(title = "修改-会议设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult<Void> edit(@RequestBody MeetingDevice meetingDevice){
        meetingDeviceService.edit(meetingDevice);
        return ApiResult.success();
    }

    /**
     * 删除
     * @param deviceUuid
     * @return
     */
    @Log(title = "删除-会议设备", businessType = BusinessType.DELETE)
    @DeleteMapping
    public ApiResult<Void> remove(@RequestParam Long deviceUuid){
        meetingDeviceService.remove(deviceUuid);
        return ApiResult.success();
    }

    /**
     * 设备人员授权（覆盖式）
     * personIds 为空字符串时解除该设备全部授权
     */
    @Log(title = "会议设备人员授权", businessType = BusinessType.UPDATE)
    @PostMapping("/bindPerson")
    public ApiResult<Void> bindPerson(@RequestBody MeetingDeviceBindPersonRequest request) {
        meetingDeviceService.bindPerson(request);
        return ApiResult.success();
    }

}

