package com.engine.recruit.controller;

import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.recruit.util.ResponseResult;
import com.engine.recruit.wrapper.ResumeRecognitionWrapper;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.Map;

/**
 * @author:dxfeng
 * @createTime: 2023/12/12
 * @version: 1.0
 */
public class ResumeRecognitionController {
    public ResumeRecognitionWrapper getResumeRecognitionWrapper(User user) {
        return ServiceUtil.getService(ResumeRecognitionWrapper.class, user);
    }

    @POST
    @Path("/resumeUpload")
    @Produces(MediaType.APPLICATION_JSON)
    public String resumeUpload(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        Map<String, Object> param = ParamUtil.request2Map(request);
        return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getResumeRecognitionWrapper(user)::resumeUpload, param);
    }

    @POST
    @Path("/importResume")
    @Produces(MediaType.APPLICATION_JSON)
    public String importResume(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        Map<String, Object> param = ParamUtil.request2Map(request);
        return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getResumeRecognitionWrapper(user)::importResume, param);
    }

    @GET
    @Path("/fetchResume")
    @Produces(MediaType.APPLICATION_JSON)
    public String fetchResume(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        Map<String, Object> param = ParamUtil.request2Map(request);
        return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getResumeRecognitionWrapper(user)::fetchResume, param);
    }
}
