package com.xhpc.card.controller;

import com.xhpc.card.domain.*;
import com.xhpc.card.service.XhpcMessageBoardService;
import com.xhpc.common.core.web.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 留言板服务Controller
 *
 * @author WH
 * @date 2022/1/10 10:02
 * @since version-1.0
 */
@RestController
@RequestMapping("/board")
@Slf4j
public class XhpcMessageBoardController {

    @Resource
    XhpcMessageBoardService xhpcMessageBoardService;

    /**
     * 平台删除所查看的用户列表中的指定用户
     *
     * @author WH
     * @date 2022/1/13 18:43
     * @since version-1.0
     */
    @PatchMapping("/platform/list/user")
    public AjaxResult deleteListUser(@Validated @RequestBody UserInfo userInfo) {

        xhpcMessageBoardService.deleteListUser(userInfo);

        return AjaxResult.success();
    }

    /**
     * 平台给用户发送消息
     *
     * @author WH
     * @date 2022/1/13 18:43
     * @since version-1.0
     */
    @PostMapping("/platform/message")
    public AjaxResult platformSendMessageToUser(@RequestBody PlatformSendMessageToUserRequest platformRequest) {

        if (platformRequest.getMessageContent() == null || "".equals(platformRequest.getMessageContent())) {
            return AjaxResult.error("必须传入有效的信息内容");
        }
        xhpcMessageBoardService.platformSendMessageToUser(platformRequest);

        return AjaxResult.success();
    }

    /**
     * 租户查询给它发送信息的用户的列表
     *
     * @author WH
     * @date 2022/1/14 10:26
     * @since version-1.0
     */
    @GetMapping("/user/list")
    public AjaxResult queryUserList(@Validated QueryUserListRequest param) throws Exception {

        QueryUserListResponse queryUserListResponse = xhpcMessageBoardService.queryUserList(param);

        return AjaxResult.success(queryUserListResponse);

    }

    /**
     * 平台查询指定用户消息
     *
     * @author WH
     * @date 2022/1/15 18:47
     * @since version-1.0
     */
    @PostMapping("/user/message")
    public AjaxResult platformQueryMessage(@RequestBody UserQueryCondition userQueryCondition) {

        QueryUserMassageResponse queryUserMassageResponse = xhpcMessageBoardService.platformQueryMessage(userQueryCondition);

        return AjaxResult.success(queryUserMassageResponse);

    }

}
