package com.yida.data.user.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.user.EduUserDevice;
import com.yida.data.user.service.EduUserDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "人脸下发记录（不鉴权）")
@RestController
@RequestMapping("/in/userDevice")
@RequiredArgsConstructor
public class InEduUserDeviceController {
    private final EduUserDeviceService eduUserDeviceService;

    @ApiOperation("批量保存")
    @PostMapping("/batchSave")
    public ResultBean<String> batchSave(@RequestBody List<EduUserDevice> list) {
        eduUserDeviceService.batchSaveUserDevice(list);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("获取设备和人员关联信息")
    @GetMapping("/listUserDevice")
    public ResultBean<List<EduUserDevice>> listUserDevice(@RequestParam Long userId, @RequestParam Integer type,
                                                          @RequestParam Long deviceId, @RequestParam Long faceGroupId) {
        List<EduUserDevice> list = eduUserDeviceService.list(Wrappers.lambdaQuery(new EduUserDevice())
                .eq(EduUserDevice::getUserId, userId)
                .eq(EduUserDevice::getUserType, type)
                .eq(EduUserDevice::getDeviceId, deviceId)
                .eq(EduUserDevice::getFaceGroupId, faceGroupId)
        );
        return ResultBean.buildSuccess(list);
    }

    @ApiOperation("删除设备和人员关联信息")
    @PostMapping("/deleteRelation")
    public ResultBean<String> deleteRelation(@RequestBody EduUserDevice userDevice) {
        eduUserDeviceService.remove(Wrappers.lambdaQuery(new EduUserDevice())
                .eq(EduUserDevice::getUserId, userDevice.getUserId())
                .eq(EduUserDevice::getUserType, userDevice.getUserType())
                .eq(EduUserDevice::getDeviceId, userDevice.getDeviceId())
                .eq(EduUserDevice::getFaceGroupId, userDevice.getFaceGroupId())
        );
        return ResultBean.buildSuccess();
    }
}
