package com.yida.data.user.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.user.EduUserFace;
import com.yida.data.user.dto.UpdateFaceGroupUserStatusDTO;
import com.yida.data.user.service.EduFaceGroupUserService;
import com.yida.data.user.service.EduUserFaceService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@ApiOperation("人脸管理（不鉴权）")
@RestController
@RequestMapping("/in/face")
@RequiredArgsConstructor
public class InEduUserFaceController {

    private final EduUserFaceService eduUserFaceService;
    private final EduFaceGroupUserService eduFaceGroupUserService;

    @GetMapping("/getFaceByUser")
    public ResultBean<EduUserFace> getFaceByUser(@RequestParam("userId") Long userId,
        @RequestParam("type") Integer type) {
        return ResultBean.buildSuccess(eduUserFaceService.getOne(
            Wrappers.lambdaQuery(new EduUserFace()).eq(EduUserFace::getUserId, userId).eq(EduUserFace::getUserType, type)));
    }

    @GetMapping("/delFaceByUser")
    public ResultBean delFaceByUser(@RequestParam("userId") Long userId,
        @RequestParam("type") Integer type) {
        eduUserFaceService.remove(
            Wrappers.lambdaQuery(new EduUserFace()).eq(EduUserFace::getUserId, userId).eq(EduUserFace::getUserType, type));
        return ResultBean.buildSuccess();
    }

    @ApiOperation("修改人脸下发状态")
    @PostMapping("/updateFaceGroupUserStatus")
    public ResultBean updateFaceGroupUserStatus(@RequestBody UpdateFaceGroupUserStatusDTO dto) {
        if (CollUtil.isNotEmpty(dto.getUserList())) {
            eduFaceGroupUserService.updateStatus(dto);
        }
        return ResultBean.buildSuccess();
    }
}
