package com.cool.store.controller.webc;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.context.PartnerUserHolder;
import com.cool.store.request.notice.StoreMessagePendingRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.MessageTemplateService;
import com.cool.store.vo.PartnerUserInfoVO;
import com.cool.store.vo.notice.MessageDetailVO;
import com.cool.store.vo.notice.ModuleAndMatterVO;
import com.cool.store.vo.notice.StoreMessageVO;
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/27 21:04
 * @Version 1.0
 */
@RestController
@RequestMapping("/mini/notice")
@Api(tags = "mini事项/通知管理")
@Slf4j
public class MiniMessageTemplateController {

    @Resource
    private MessageTemplateService messageTemplateService;

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

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

}
