using SqlSugar;
using Volo.Abp.Domain.Entities.Auditing;

namespace Yi.Framework.AiHub.Domain.Entities;

/// <summary>
/// 用量统计
/// </summary>
[SugarTable("Ai_UsageStatistics")]
public class UsageStatisticsAggregateRoot : FullAuditedAggregateRoot<Guid>
{
    public UsageStatisticsAggregateRoot()
    {
    }

    public UsageStatisticsAggregateRoot(Guid userId, string modelId)
    {
        UserId = userId;
        ModelId = modelId;
    }

    /// <summary>
    /// 用户id
    /// </summary>
    public Guid UserId { get; set; }

    /// <summary>
    /// 哪个模型
    /// </summary>
    public string ModelId { get; set; }

    /// <summary>
    /// 对话次数
    /// </summary>
    public int UsageTotalNumber { get; set; }

    /// <summary>
    /// 使用输出token总数
    /// </summary>
    public int UsageOutputTokenCount { get; set; }

    /// <summary>
    /// 使用输入总数
    /// </summary>
    public int UsageInputTokenCount { get; set; }

    /// <summary>
    /// 总token使用数量
    /// </summary>
    public int TotalTokenCount { get; set; }

    /// <summary>
    /// 新增一次聊天统计
    /// </summary>
    public void AddOnceChat(int inputTokenCount, int outputTokenCount)
    {
        UsageTotalNumber += 1;
        UsageOutputTokenCount += outputTokenCount;
        UsageInputTokenCount += inputTokenCount;
        TotalTokenCount += (outputTokenCount + inputTokenCount);
    }
}