package com.cool.store.controller.webb;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.context.LoginUserInfo;
import com.cool.store.dto.notice.NoticeDTO;
import com.cool.store.request.notice.*;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.MessageTemplateService;
import com.cool.store.vo.notice.*;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author suzhuhong
 * @Date 2025/7/25 15:08
 * @Version 1.0
 */
@RestController
@RequestMapping("/pc/notice")
@Api(tags = "PC事项/通知管理")
@Slf4j
public class MessageTemplateController {


    @Resource
    MessageTemplateService messageTemplateService;


    @PostMapping("/add")
    @ApiOperation("新增消息通知")
    public ResponseResult<Boolean> messageTemplateService(@RequestBody MessageTemplateAddRequest request) {
        return ResponseResult.success(messageTemplateService.addMessageTemplate(request, CurrentUserHolder.getUser()));
    }

    @PostMapping("/edit")
    @ApiOperation("编辑消息通知")
    public ResponseResult<Boolean> editMessageTemplate(@RequestBody MessageTemplateAddRequest request) {
        return ResponseResult.success(messageTemplateService.editMessageTemplate(request, CurrentUserHolder.getUser()));
    }

    @ApiOperation("通知详情")
    @GetMapping("/getMessageTemplateDetail")
    public ResponseResult<MessageTemplateDetailVO> getMessageTemplateDetail(@RequestParam("id")Long id) {
        return ResponseResult.success(messageTemplateService.getMessageTemplateDetail(id));
    }

    @PostMapping("/batchDelete")
    @ApiOperation("批量删除")
    public ResponseResult<Boolean> editMessageTemplate(@RequestBody BatchDeletedRequest request) {
        return ResponseResult.success(messageTemplateService.batchDeleteMessageTemplate(request, CurrentUserHolder.getUser()));
    }

    @PostMapping("/batchPublish")
    @ApiOperation("批量发布")
    public ResponseResult<Boolean> batchPublishMessageTemplate(@RequestBody BatchPublishRequest request) {
        messageTemplateService.batchPublishMessageTemplate(request, CurrentUserHolder.getUser().getUserId());
        return ResponseResult.success(Boolean.TRUE);
    }

    @PostMapping("/getMessageTemplateList")
    @ApiOperation("通知管理列表/事项管理列表")
    public ResponseResult<PageInfo<NoticeDTO>> getMessageTemplateList(@RequestBody MessageTemplateQueryRequest request) {
        return ResponseResult.success(messageTemplateService.getMessageTemplateList(request));
    }

    @PostMapping("/getStoreMessageListByTemplateId")
    @ApiOperation("进度管理")
    public ResponseResult<PageInfo<StoreMessageDetailVO>> getStoreMessageListByTemplateId(@RequestBody StoreMessageRequest request) {
        return ResponseResult.success(messageTemplateService.getStoreMessageListByTemplateId(request));
    }

    @PostMapping("/batchRevokeNotice")
    @ApiOperation("批量撤销")
    public ResponseResult<Boolean> batchRevokeNotice(@RequestBody BatchRevokeRequest request) {
        return ResponseResult.success(messageTemplateService.batchRevokeNotice(request,CurrentUserHolder.getUser()));
    }

    @ApiOperation("撤销单个门店消息")
    @GetMapping("/revokeById")
    public ResponseResult<Boolean> revokeById(@RequestParam("id")Long id) {
        return ResponseResult.success(messageTemplateService.revokeById(id,CurrentUserHolder.getUser()));
    }

    @ApiOperation("获取每个门店需要展示的模块")
    @GetMapping("/getModuleListByStoreId")
    public ResponseResult<List<ModuleAndMatterVO>> getModuleListByStoreId(@RequestParam("id")String storeId) {
        return ResponseResult.success(messageTemplateService.getModuleList(storeId, CurrentUserHolder.getUser().getMobile()));
    }

    @ApiOperation("获取消息详情")
    @GetMapping("/getMessageDetail")
    public ResponseResult<MessageDetailVO> getMessageDetail(@RequestParam("id")Long id) {
        return ResponseResult.success(messageTemplateService.getMessageDetail(id));
    }

    @ApiOperation("待办列表/模块列表")
    @PostMapping("/getStorePendingList")
    public ResponseResult<PageInfo<StoreMessageVO>> getStorePendingList(@RequestBody StoreMessagePendingRequest request) {
        return ResponseResult.success(messageTemplateService.getStorePendingList(request));
    }

    @ApiOperation("确认已读")
    @GetMapping("/readMessage")
    public ResponseResult<Boolean> readMessage(@RequestParam("id")Long id) {
        return ResponseResult.success(messageTemplateService.readMessage(id, CurrentUserHolder.getUser().getMobile()));
    }

    @ApiOperation("确认已处理")
    @GetMapping("/handleMessage")
    public ResponseResult<Boolean> handleMessage(@RequestParam("id")Long id) {
        LoginUserInfo user = CurrentUserHolder.getUser();
        return ResponseResult.success(messageTemplateService.handleMessage(id, user.getName(), user.getMobile()));
    }
}
