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.InductionManageWrapper;
import com.engine.recruit.wrapper.OfferWrapper;
import com.engine.recruit.wrapper.RecruitInterviewWrapper;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.Map;

/**
 * @author:dxfeng
 * @createTime: 2023/11/15
 * @version: 1.0
 */
public class RecruitMobileModeController {
    public OfferWrapper getOfferWrapper(User user) {
        return ServiceUtil.getService(OfferWrapper.class, user);
    }

    public InductionManageWrapper getInductionManageWrapper(User user) {
        return ServiceUtil.getService(InductionManageWrapper.class, user);
    }

    public RecruitInterviewWrapper getRecruitInterviewWrapper(User user) {
        return ServiceUtil.getService(RecruitInterviewWrapper.class, user);
    }

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

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

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

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


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

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