using HoneyBox.Admin.Business.Attributes;
using HoneyBox.Admin.Business.Models.Statistics;
using HoneyBox.Admin.Business.Services.Interfaces;
using Microsoft.AspNetCore.Mvc;

namespace HoneyBox.Admin.Business.Controllers;

/// <summary>
/// 统计报表控制器
/// </summary>
[Route("api/admin/business/statistics")]
public class StatisticsController : BusinessControllerBase
{
    private readonly IStatisticsService _statisticsService;

    public StatisticsController(IStatisticsService statisticsService)
    {
        _statisticsService = statisticsService;
    }

    /// <summary>
    /// 获取今日订单统计数据
    /// </summary>
    /// <returns>今日订单统计</returns>
    [HttpGet("today-order")]
    [BusinessPermission("statistics:view")]
    public async Task<IActionResult> GetTodayOrderStats()
    {
        var result = await _statisticsService.GetTodayOrderStatsAsync();
        return Ok(result);
    }

    /// <summary>
    /// 获取货币信息统计数据
    /// </summary>
    /// <returns>货币信息统计</returns>
    [HttpGet("currency-info")]
    [BusinessPermission("statistics:view")]
    public async Task<IActionResult> GetCurrencyInfoStats()
    {
        var result = await _statisticsService.GetCurrencyInfoStatsAsync();
        return Ok(result);
    }

    /// <summary>
    /// 获取收入汇总统计数据
    /// </summary>
    /// <returns>收入汇总统计</returns>
    [HttpGet("income-summary")]
    [BusinessPermission("statistics:view")]
    public async Task<IActionResult> GetIncomeSummaryStats()
    {
        var result = await _statisticsService.GetIncomeSummaryStatsAsync();
        return Ok(result);
    }

    /// <summary>
    /// 获取用户统计数据
    /// </summary>
    /// <returns>用户统计</returns>
    [HttpGet("user-stats")]
    [BusinessPermission("statistics:view")]
    public async Task<IActionResult> GetUserStats()
    {
        var result = await _statisticsService.GetUserStatsAsync();
        return Ok(result);
    }

    /// <summary>
    /// 获取单个盒子的统计数据
    /// </summary>
    /// <param name="goodsId">盒子ID</param>
    /// <param name="startTime">开始时间</param>
    /// <param name="endTime">结束时间</param>
    /// <returns>盒子统计数据</returns>
    [HttpGet("box-statistics")]
    [BusinessPermission("statistics:view")]
    public async Task<IActionResult> GetBoxStatistics(
        [FromQuery] int goodsId,
        [FromQuery] DateTime? startTime,
        [FromQuery] DateTime? endTime)
    {
        var request = new BoxStatisticsRequest
        {
            GoodsId = goodsId,
            StartTime = startTime,
            EndTime = endTime
        };

        var result = await _statisticsService.GetBoxStatisticsAsync(request);
        return Ok(result);
    }

    /// <summary>
    /// 获取盒子利润统计列表
    /// </summary>
    /// <param name="request">请求参数</param>
    /// <returns>盒子利润统计列表</returns>
    [HttpGet("box-profit-list")]
    [BusinessPermission("statistics:view")]
    public async Task<IActionResult> GetBoxProfitList([FromQuery] BoxProfitListRequest request)
    {
        var result = await _statisticsService.GetBoxProfitListAsync(request);
        return Ok(result);
    }

    /// <summary>
    /// 获取所有盒子的汇总统计数据
    /// </summary>
    /// <param name="goodsId">盒子ID</param>
    /// <param name="title">盒子名称</param>
    /// <param name="status">状态</param>
    /// <param name="type">盒子类型</param>
    /// <param name="startTime">开始时间</param>
    /// <param name="endTime">结束时间</param>
    /// <returns>汇总统计数据</returns>
    [HttpGet("summary-statistics")]
    [BusinessPermission("statistics:view")]
    public async Task<IActionResult> GetSummaryStatistics(
        [FromQuery] int? goodsId,
        [FromQuery] string? title,
        [FromQuery] int? status,
        [FromQuery] int? type,
        [FromQuery] DateTime? startTime,
        [FromQuery] DateTime? endTime)
    {
        var request = new BoxSummaryStatisticsRequest
        {
            GoodsId = goodsId,
            Title = title,
            Status = status,
            Type = type,
            StartTime = startTime,
            EndTime = endTime
        };

        var result = await _statisticsService.GetSummaryStatisticsAsync(request);
        return Ok(result);
    }
}
