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.RecruitPositionWrapper;
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/10/09
 * @version: 1.0
 */
public class RecruitPositionController {
    public RecruitPositionWrapper getRecruitPositionWrapper(User user) {
        return ServiceUtil.getService(RecruitPositionWrapper.class, user);
    }

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

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

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

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

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

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

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

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