package com.community.huiju.controller;

import com.community.commom.constant.Constant;
import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.service.FaceServiceI;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;

@RestController
@RefreshScope
@RequestMapping("/")
@Api(value = "人脸相关API", description = "人脸相关API")
public class FaceController extends BaseController {
    @Autowired
    private FaceServiceI faceServicel;

    @ApiOperation(value = "添加人脸图片", notes = "添加人脸图片")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "otherUserId",value = "家属或租户ID,不填为本人")
    })

    @RequestMapping(value = "/addFace",method = RequestMethod.POST)
    public Object getTaFace(HttpSession session,
                            @ApiParam(value = "file" ,required = true) MultipartFile uploadFile,
                            @RequestParam(required = false) Integer otherUserId){
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = faceServicel.addFace(userElement ,uploadFile,otherUserId);
        return responseBean;
    }

    @ApiOperation(value = "修改人脸图片", notes = "修改人脸图片")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "otherUserId",value = "家属或租户ID,不填为本人"),
    })
    @RequestMapping(value = "/upDateFace",method = RequestMethod.POST)
    public Object upDateTaFace(HttpSession session,
                               @ApiParam(value = "file" ,required = true) MultipartFile uploadFile,
                               @RequestParam(required = false) Integer otherUserId
                               ){
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
         responseBean = faceServicel.upDateFace(userElement,uploadFile,otherUserId);
        return responseBean;
    }

    @ApiOperation(value = "获取当前已录入人脸信息", notes = "获取当前已录入人脸信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "otherUserId",value = "家属或租户ID,不填为本人"),
    })
    @RequestMapping(value = "/getUserIdFace",method = RequestMethod.GET)
    public Object getTaFaceByUserId(HttpSession session, @RequestParam(required = false) Integer otherUserId){
        UserElement userElement = getUserElement(session);
        ResponseBean responseBean = faceServicel.getTaFaceByUserId(userElement,otherUserId);
        return responseBean;
    }
    @ApiOperation(value = "删除当前人脸信息", notes = "删除当前人脸信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "otherUserId",value = "家属或租户ID,不填为本人"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "verifyId",value = "审核ID"),
    })
    @RequestMapping(value = "/deleteFace",method = RequestMethod.GET)
    public Object deleteFace(HttpSession session, @RequestParam(required = false) Integer otherUserId,
                            @RequestParam(required = false) Integer verifyId){
        UserElement userElement = getUserElement(session);
        ResponseBean responseBean = faceServicel.deleteFace(userElement,otherUserId,verifyId);
        return responseBean;
    }

}
