package com.engine.salary.report.web;

import com.engine.common.util.ServiceUtil;
import com.engine.salary.common.BaseQueryParam;
import com.engine.salary.report.entity.dto.SalaryStatisticsPushDetail;
import com.engine.salary.report.entity.dto.SalaryStatisticsPushTableDTO;
import com.engine.salary.report.entity.param.SalaryStatisticsPushDetailParam;
import com.engine.salary.report.entity.param.SalaryStatisticsPushParam;
import com.engine.salary.report.service.SalaryStatisticsPushService;
import com.engine.salary.report.service.impl.SalaryStatisticsPushServiceImpl;
import com.engine.salary.util.ResponseResult;
import com.engine.salary.util.page.PageInfo;
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.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.Map;

/**
 * @author Harryxzy
 * @ClassName SalaryStatisticsPushController
 * @date 2023/09/11 10:08
 * @description 薪酬统计报表消息推送
 */
public class SalaryStatisticsPushController {


    private SalaryStatisticsPushService getSalaryStatisticsPushService(User user) {
        return ServiceUtil.getService(SalaryStatisticsPushServiceImpl.class, user);
    }


    /**
     * 获取发送消息form
     *
     * @return obj
     */
    @GET
    @Path("/getForm")
    @Produces(MediaType.APPLICATION_JSON)
    public String getPushForm(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<Void, Map<String, Object>>(user).run(getSalaryStatisticsPushService(user)::getPushForm);
    }

    /**
     * 获取分享记录列表
     *
     * @return obj
     */
    @POST
    @Path("/getTable")
    @Produces(MediaType.APPLICATION_JSON)
    public String getPushTable(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody BaseQueryParam param) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<BaseQueryParam, PageInfo<SalaryStatisticsPushTableDTO>>(user).run(getSalaryStatisticsPushService(user)::getPushTable, param);
    }

    /**
     * 获取发送消息记录详情
     *
     * @return obj
     */
    @POST
    @Path("/getDetail")
    @Produces(MediaType.APPLICATION_JSON)
    public String getPushDetail(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SalaryStatisticsPushDetailParam param) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<SalaryStatisticsPushDetailParam, SalaryStatisticsPushDetail>(user).run(getSalaryStatisticsPushService(user)::getPushDetail, param);
    }


    /**
     * 分享报表
     *
     * @return obj
     */
    @POST
    @Path("/sendMsg")
    @Produces(MediaType.APPLICATION_JSON)
    public String push(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SalaryStatisticsPushParam param) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<SalaryStatisticsPushParam, Void>(user).run(getSalaryStatisticsPushService(user)::push, param);
    }

    /**
     * 追加分享人发送消息
     *
     * @return obj
     */
    @POST
    @Path("/addSharedSendMsg")
    @Produces(MediaType.APPLICATION_JSON)
    public String addSharePush(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SalaryStatisticsPushParam param) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<SalaryStatisticsPushParam, String>(user).run(getSalaryStatisticsPushService(user)::addSharedPush, param);
    }

//    /**
//     * 发送消息
//     *
//     * @return obj
//     */
//    @GetMapping("/reSendMsg")
//    @ApiOperation("重新发送消息")
//    @WeaPermission(publicPermission = true)
//    public WeaResult<String> push(@RequestParam Long id) {
//        salaryStatisticsPushService.rePush(id, UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey());
//        return WeaResult.success("");
//    }

    /**
     * 撤回消息
     *
     * @return obj
     */
    @GET
    @Path("/cancel")
    @Produces(MediaType.APPLICATION_JSON)
    public String cancel(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("id") Long id) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<Long, Void>(user).run(getSalaryStatisticsPushService(user)::cancel, id);
    }

    /**
     * 撤回全部消息
     *
     * @return obj
     */
    @GET
    @Path("/cancelAll")
    @Produces(MediaType.APPLICATION_JSON)
    public String cancelAll(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("id") Long id) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<Long, Void>(user).run(getSalaryStatisticsPushService(user)::cancelAll, id);
    }

}
