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.ApplicantResumeWrapper;
import weaver.general.Util;
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/09/20
 * @version: 1.0
 */
public class ApplicantResumeController {
    public ApplicantResumeWrapper getApplicantResumeWrapper(User user) {
        return ServiceUtil.getService(ApplicantResumeWrapper.class, user);
    }

    @POST
    @Path("/getApplicantsName")
    @Produces(MediaType.APPLICATION_JSON)
    public String getApplicantsName(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        Map<String, Object> params = ParamUtil.request2Map(request);
        String ids = Util.null2String(params.get("ids"));
        return new ResponseResult<String, Map<String, Object>>(user).run(getApplicantResumeWrapper(user)::getApplicantsName, ids);
    }

    @POST
    @Path("/getInterviewInfoById")
    @Produces(MediaType.APPLICATION_JSON)
    public String getInterviewInfoById(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        Map<String, Object> params = ParamUtil.request2Map(request);
        String id = Util.null2String(params.get("id"));
        return new ResponseResult<String, Map<String, Object>>(user).run(getApplicantResumeWrapper(user)::getInterviewInfoById, id);
    }

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

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

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


    @POST
    @Path("/checkRepeatResume")
    @Produces(MediaType.APPLICATION_JSON)
    public String checkRepeatResume(@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(getApplicantResumeWrapper(user)::checkRepeatResume, param);
    }

    @GET
    @Path("/getResumeCardInfo")
    @Produces(MediaType.APPLICATION_JSON)
    public String getResumeCardInfo(@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(getApplicantResumeWrapper(user)::getResumeCardInfo, param);
    }

    @GET
    @Path("/getResumeListStatus")
    @Produces(MediaType.APPLICATION_JSON)
    public String getResumeListStatus(@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>, String>(user).run(getApplicantResumeWrapper(user)::getResumeListStatus, param);
    }

    @GET
    @Path("/updateResumeListStatus")
    @Produces(MediaType.APPLICATION_JSON)
    public String updateResumeListStatus(@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(getApplicantResumeWrapper(user)::updateResumeListStatus, param);
    }
}
