package com.engine.salary.process.siArchives;

import com.engine.common.util.ServiceUtil;
import com.engine.salary.entity.siarchives.param.SIArchiveImportParam;
import com.engine.salary.enums.siaccount.EmployeeStatusEnum;
import com.engine.salary.service.SISchemeService;
import com.engine.salary.service.impl.SISchemeServiceImpl;
import com.engine.salary.util.ResponseResult;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.extern.slf4j.Slf4j;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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: sy
 * @Description: 社保福利档案流程使用
 * @Date: 2022/11/10
 **/
@Slf4j
public class SIArchiveActionAPI {

    private SISchemeService getService(User user) {
        return ServiceUtil.getService(SISchemeServiceImpl.class,user);
    }

    /**
     * 前置校验、列表添加接口
     * @param importData
     * @return
     */
    @POST
    @Path("/checkImportSIArchiveListAdd")
    @Produces(MediaType.APPLICATION_JSON)
    public String checkImportSIArchiveListAdd(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SIArchiveImportParam importData) {
        User user = HrmUserVarify.getUser(request, response);
        importData.setRunStatus(EmployeeStatusEnum.STAY_ADD.getValue());
        importData.setAddData(false);
        return new ResponseResult<SIArchiveImportParam, Map<String, Object>>(user).run(getService(user)::checkSIArchiveAdd, importData);
    }

    /**
     * 新增社保福利档案
     * @param importData
     * @return
     */
    @POST
    @Path("/addSIArchive")
    @Produces(MediaType.APPLICATION_JSON)
    public String addSIArchive(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SIArchiveImportParam importData) {
        User user = HrmUserVarify.getUser(request, response);
        importData.setRunStatus(EmployeeStatusEnum.STAY_ADD.getValue());
        importData.setAddData(true);
        return new ResponseResult<SIArchiveImportParam, Map<String, Object>>(user).run(getService(user)::addSIArchive, importData);
    }
}
