using CloudGaming.Api.Base;
using CloudGaming.Code.DataAccess;
using CloudGaming.Code.Other;
using CloudGaming.DtoModel.Messages;

using HuanMeng.DotNetCore.Base;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace CloudGaming.Api.Controllers;

/// <summary>
/// 消息
/// </summary>
public class MessagesController : CloudGamingControllerBase
{
    public MessagesController(IServiceProvider _serviceProvider) : base(_serviceProvider)
    {
    }

    /// <summary>
    /// 获取用户消息列表
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<List<MessageListDto>> GetUserMessageList()
    {
        MessagesBLL messagesBLL = new MessagesBLL(ServiceProvider);
        return await messagesBLL.GetUserMessageList();
    }

    /// <summary>
    /// 获取消息详情，获取详情后会自动已读
    /// </summary>
    /// <param name="messageId"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<MessageListDto> GetUserMessageInfo([FromQuery] int messageId)
    {
        MessagesBLL messagesBLL = new MessagesBLL(ServiceProvider);
        return await messagesBLL.GetUserMessageInfo(messageId);
    }

    /// <summary>
    /// 用户消息读取
    /// </summary>
    /// <param name="messageId"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<bool> UserMessageRead([FromBody] UserMessageRequest userMessageRequest)
    {
        MessagesBLL messagesBLL = new MessagesBLL(ServiceProvider);
        return await messagesBLL.UserMessageRead(userMessageRequest.MessageId);
    }

    /// <summary>
    /// 全部已读
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    public async Task<bool> UserAllMessageRead()
    {
        MessagesBLL messagesBLL = new MessagesBLL(ServiceProvider);
        return await messagesBLL.UserAllMessageRead();
    }

    /// <summary>
    /// 获取未读取消息的数量
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<int> GetUserMessageNotReadCount()
    {
        MessagesBLL messagesBLL = new MessagesBLL(ServiceProvider);
        return await messagesBLL.GetUserMessageNotReadCount();
    }
}
