package jnpf.memberLog.controller;

import jnpf.base.ActionResult;
import jnpf.memberLog.service.LogService;
import jnpf.model.memberLog.dto.LogAgentAlertDto;
import jnpf.model.memberLog.dto.LogMemberLogDto;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * describe
 *
 * @author HuangLinPan
 * @date 2023/08/07
 */
@RestController
@RequestMapping(value = "/log")
public class LogController {
    @Resource
    private LogService logService;


    /**
     * 获取模板列表
     */
    @GetMapping("/template/list")
    public ActionResult getTemplateList()  {
        return ActionResult.success(logService.getTemplateList());
    }

    /**
     * web--日志类型的下拉框筛选
     */
    @GetMapping("/getTemplateList")
    public ActionResult getTemplateNameList()  {
        return ActionResult.success(logService.getTemplateNameList());
    }
    /**
     * 新增日志
     * @param logMemberLogDto 日志信息
     * @return 返回值
     */
    @PostMapping()
    public ActionResult addLog(@RequestBody LogMemberLogDto logMemberLogDto)  {
        logService.addLog(logMemberLogDto);
        return ActionResult.success(logMemberLogDto.getId());
    }

    /**
     * 给工作日志相关人员发im消息
     * @param dto
     * @return
     */
    @PostMapping("/agentAlert")
    public ActionResult<Void> agentAlert(@RequestBody LogAgentAlertDto dto)  {
        logService.agentAlert(dto);
        return ActionResult.success();
    }

    /**
     * 获取日志详情
     * @param logId 日志id
     * @return 返回值
     */
    @GetMapping("/detail/{logId}")
    public ActionResult getLogDetail(@PathVariable("logId") String logId)  {
        return ActionResult.success(logService.getLogDetail(logId));
    }
    /**
     * 获取日志详情
     * @param logId 日志id
     * @return 返回值
     */
    @GetMapping("/webDetail/{logId}")
    public ActionResult getWebLogDetail(@PathVariable("logId") String logId)  {
        return ActionResult.success(logService.getLogDetail(logId));
    }

    /**
     * 点击日志接收人出现的列表--接收范围
     * @param logId 日志id
     * @return 返回值
     */
    @GetMapping("/receiveRange/{logId}")
    public ActionResult getReceiveRange(@PathVariable("logId") String logId)  {
        return ActionResult.success(logService.getReceiveRange(logId));
    }

    /**
     * 点击日志接收人出现的列表--已读
     * @param logId 日志id
     * @return 返回值
     */
    @GetMapping("/read/{logId}")
    public ActionResult getReadList(@PathVariable("logId") String logId)  {
        return ActionResult.success(logService.getReadList(logId));
    }

    /**
     * 点击日志接收人出现的列表--未读
     * @param logId 日志id
     * @return 返回值
     */
    @GetMapping("/unread/{logId}")
    public ActionResult getUnReadList(@PathVariable("logId") String logId)  {
        return ActionResult.success(logService.getUnReadList(logId));
    }


    /** 
     * 点击日志接收人出现的列表--点赞列表
     * @param logId 日志id
     * @return 返回值
     */
    @GetMapping("/like/{logId}")
    public ActionResult getLikeList(@PathVariable("logId") String logId)  {
        return ActionResult.success(logService.getLikeList(logId));
    }

    /**
     * 修改日志
     * @param logId 日志id
     * @param logMemberLogDto 日志信息
     * @return 返回值
     */
    @PutMapping("/{logId}")
    public ActionResult updateLog(@PathVariable("logId") String logId,@RequestBody LogMemberLogDto logMemberLogDto)  {
        logMemberLogDto.setId(logId);
        logService.updateLog(logMemberLogDto);
        return ActionResult.success();
    }

    /**
     * 删除指定日志
     * @param logId 日志id
     */
    @DeleteMapping("/{logId}")
    public ActionResult deleteLog(@PathVariable("logId") String logId)  {
        Integer i = logService.deleteLog(logId);
        if (i == -1){
            return ActionResult.fail("未找到该数据!");
        }
        if (i == -2){
            return ActionResult.fail("不能删除其他人的日志!");
        }
        return ActionResult.success();
    }

}
