package com.xhpc.card.api;

import com.xhpc.card.domain.QueryUserMassageResponse;
import com.xhpc.card.domain.SendMessageToPlatformRequest;
import com.xhpc.card.domain.UserQueryCondition;
import com.xhpc.card.service.XhpcMessageBoardService;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.log.annotation.Log;
import com.xhpc.common.log.enums.BusinessType;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 小程序的InvoiceController
 *
 * @author WH
 * @date 2021/12/23 13:49
 * @since version-1.0
 */
@RestController
@RequestMapping("/api/message-board")
public class XhpcMessageBoardApiController extends BaseController {

    @Resource
    XhpcMessageBoardService xhpcMessageBoardService;

    /**
     * 用户发起聊天，发送聊天记录给平台客服
     *
     * @author WH
     * @date 2021/12/28 18:51
     * @since version-1.0
     */
    @PostMapping("/user/message")
    @Log(title = "留言板-用户发送聊天信息", businessType = BusinessType.INSERT)
    public AjaxResult sendMessageToPlatform(@RequestBody SendMessageToPlatformRequest userMessage) {

        xhpcMessageBoardService.writeUserMessageToDb(userMessage);
        return AjaxResult.success();
    }

    /**
     * 用户查看所发送的聊天记录
     *
     * @author WH
     * @date 2022/1/13 18:15
     * @since version-1.0
     */
    @GetMapping("/user/messageYu")
    public AjaxResult queryUserMessage(UserQueryCondition userQueryCondition) {

        QueryUserMassageResponse queryUserMassageResponse = xhpcMessageBoardService.queryUserMessage(userQueryCondition);
        return AjaxResult.success(queryUserMassageResponse);
    }

    /**
     * 获取用户对应的租户的头像
     *
     * @author WH
     * @date 2022/1/13 18:19
     * @since version-1.0
     */
    @GetMapping("/platform-icon")
    public AjaxResult returnPlatformAvatar(@Param("tenantId") String tenantId, @Param("tenantType") Integer tenantType) {

        String avatarAddress = xhpcMessageBoardService.returnPlatformAvatar(tenantId, tenantType);
        return AjaxResult.success(avatarAddress);
    }

}
