package com.engine.salary.web;

import com.engine.common.util.ServiceUtil;
import com.engine.salary.entity.salaryBill.dto.SalarySendRangeListDTO;
import com.engine.salary.entity.salaryBill.param.SalarySendRangeQueryParam;
import com.engine.salary.entity.salaryBill.param.SalarySendRangeSaveParam;
import com.engine.salary.util.ResponseResult;
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.wrapper.SalarySendRangeWrapper;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
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.Collection;

/**
 * @Description: 工资单范围
 */
public class SalarySendRangeController {
    private SalarySendRangeWrapper getSalarySendRangeWrapper(User user) {
        return ServiceUtil.getService(SalarySendRangeWrapper.class, user);
    }

    @POST
    @Path("/save")
    @Produces(MediaType.APPLICATION_JSON)
    public String save(@Context HttpServletRequest request, @Context HttpServletResponse response,
                       @RequestBody SalarySendRangeSaveParam saveParam) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<SalarySendRangeSaveParam, Void>(user).run(getSalarySendRangeWrapper(user)::save, saveParam);
    }

    @POST
    @Path("/delete")
    @Produces(MediaType.APPLICATION_JSON)
    public String deleteByIds(@Context HttpServletRequest request, @Context HttpServletResponse response,
                              @RequestBody Collection<Long> ids) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<Collection<Long>, Void>(user).run(getSalarySendRangeWrapper(user)::deleteByIds, ids);
    }

    @POST
    @Path("/list")
    @Produces(MediaType.APPLICATION_JSON)
    public String save(@Context HttpServletRequest request, @Context HttpServletResponse response,
                       @RequestBody SalarySendRangeQueryParam queryParam) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<SalarySendRangeQueryParam, PageInfo<SalarySendRangeListDTO>>(user).run(getSalarySendRangeWrapper(user)::listPage, queryParam);
    }

}
