package com.zhongshu.card.server.core.controller.projectAbout;

import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.model.base.*;
import com.zhongshu.card.client.model.projectAbout.orgFace.*;
import com.zhongshu.card.client.type.common.AuditState;
import com.zhongshu.card.server.core.service.projectAbout.OrgUserFaceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 项目人员人脸管理
 *
 * @author TRX
 * @date 2024/7/26
 */
@RestController
@RequestMapping("/orgUserFace")
@Tag(name = "项目-用户人脸设置")
public class OrgUserFaceController {

    @Autowired
    private OrgUserFaceService orgUserFaceService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "保存人脸信息（当前用户）", description = "保存人脸信息")
    @RequestMapping(value = "saveFace", method = {RequestMethod.POST})
    public ResultContent saveFace(@RequestBody @Valid OrgUserFaceParam param) {
        param.setIsManager(Boolean.FALSE);
        return orgUserFaceService.saveFace(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "保存人脸信息（管理员）", description = "保存人脸信息")
    @RequestMapping(value = "managerSaveFace", method = {RequestMethod.POST})
    public ResultContent managerSaveFace(@RequestBody @Valid OrgUserFaceParam param) {
        param.setIsManager(Boolean.TRUE);
        return orgUserFaceService.saveFace(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "删除人脸信息", description = "删除人脸信息")
    @RequestMapping(value = {"deleteFace"}, method = {RequestMethod.POST})
    public ResultContent deleteFace(@RequestBody IDParam param) {
        return orgUserFaceService.deleteFace(param.getId(), false);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "删除人脸信息(多个)", description = "删除人脸信息")
    @RequestMapping(value = {"deleteFaces"}, method = {RequestMethod.POST})
    public ResultContent deleteFaces(@RequestBody IDsParam param) {
        return orgUserFaceService.deleteFace(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "审核人脸申请", description = "审核人脸申请")
    @RequestMapping(value = {"auditFace"}, method = {RequestMethod.POST})
    public ResultContent auditFace(@RequestBody OrgUserFaceAuditParam param) {
        return orgUserFaceService.auditFace(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "审核人脸申请(多个)", description = "审核人脸申请(多个)")
    @RequestMapping(value = {"auditsFace"}, method = {RequestMethod.POST})
    public ResultContent auditsFace(@RequestBody OrgUserFaceAuditsParam param) {
        return orgUserFaceService.auditsFace(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "所有数据列表-分页查询", description = "数据列表-分页查询")
    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
    public ResultContent<Page<OrgUserFaceModel>> page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable, @Parameter(required = false) OrgUserFaceSearch param) {
        Assert.hasText(param.getProjectOid(), "projectOid不能为空");
        return orgUserFaceService.page(param, pageable);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "所有数据列表（已通过的）-分页查询", description = "数据列表-分页查询")
    @RequestMapping(value = {"passPage"}, method = {RequestMethod.POST})
    public ResultContent<Page<OrgUserFaceModel>> passPage(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable, @Parameter(required = false) OrgUserFaceSearch param) {
        Assert.hasText(param.getProjectOid(), "projectOid不能为空");
        param.setAuditState(AuditState.Audited);
        return orgUserFaceService.page(param, pageable);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到当前用户人脸信息列表", description = "得到当前用户人脸信息列表")
    @RequestMapping(value = "getCurrentUserAllFace", method = {RequestMethod.POST})
    public ResultContent getCurrentUserAllFace(@RequestBody @Valid ProjectOidParam param) {
        return orgUserFaceService.getCurrentUserAllFace(param.getProjectOid());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到指定用户人脸信息列表", description = "得到指定用户人脸信息列表")
    @RequestMapping(value = "getUserFace", method = {RequestMethod.POST})
    public ResultContent getUserFace(@RequestBody @Valid UserIdAndOidModel param) {
        return orgUserFaceService.getUserAllFace(param.getUserId(), param.getProjectOid());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到指定用户人脸信息列表(已审核通过的)", description = "得到指定用户人脸信息列表")
    @RequestMapping(value = "getUserAllFacePass", method = {RequestMethod.POST})
    public ResultContent getUserAllFacePass(@RequestBody @Valid UserIdAndOidModel param) {
        return orgUserFaceService.getUserAllFacePass(param.getUserId(), param.getProjectOid());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "人脸信息详情", description = "人脸信息详情")
    @RequestMapping(value = "getDetail", method = {RequestMethod.POST})
    public ResultContent getDetail(@RequestBody @Valid IDParam param) {
        return orgUserFaceService.getDetail(param.getId());
    }

    @Operation(summary = "判断检查人脸可信度", description = "判断检查人脸可信度")
    @RequestMapping(value = "conformFace", method = {RequestMethod.POST})
    public ResultContent conformFace(@RequestBody @Valid UrlParam param) {
        return orgUserFaceService.conformFace(param.getUrl(), param.getProjectOid());
    }

}
