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

namespace Yi.Framework.AiHub.Domain.Entities;

/// <summary>
/// 邀请记录
/// </summary>
[SugarTable("Ai_InvitationRecord")]
[SugarIndex($"index_{nameof(InviterId)}_{nameof(InvitedUserId)}",
    nameof(InviterId), OrderByType.Asc,
    nameof(InvitedUserId), OrderByType.Asc)]
[SugarIndex($"index_{nameof(InvitedUserId)}", nameof(InvitedUserId), OrderByType.Asc)]
public class InvitationRecordAggregateRoot : FullAuditedAggregateRoot<Guid>
{
    public InvitationRecordAggregateRoot()
    {
    }

    public InvitationRecordAggregateRoot(Guid inviterId, Guid invitedUserId, string inviteCode)
    {
        InviterId = inviterId;
        InvitedUserId = invitedUserId;
        InviteCode = inviteCode;
        InvitationTime = DateTime.Now;
        Status = InvitationStatus.Valid;
    }

    /// <summary>
    /// 邀请人ID
    /// </summary>
    public Guid InviterId { get; set; }

    /// <summary>
    /// 被邀请人ID
    /// </summary>
    public Guid InvitedUserId { get; set; }

    /// <summary>
    /// 使用的邀请码
    /// </summary>
    [SugarColumn(Length = 50)]
    public string InviteCode { get; set; } = string.Empty;

    /// <summary>
    /// 邀请时间
    /// </summary>
    public DateTime InvitationTime { get; set; }

    /// <summary>
    /// 邀请状态（0=有效，1=已撤销）
    /// </summary>
    public InvitationStatus Status { get; set; }

    /// <summary>
    /// 备注信息
    /// </summary>
    [SugarColumn(Length = 500, IsNullable = true)]
    public string? Remark { get; set; }
}

/// <summary>
/// 邀请状态枚举
/// </summary>
public enum InvitationStatus
{
    /// <summary>
    /// 有效
    /// </summary>
    Valid = 0,

    /// <summary>
    /// 已撤销
    /// </summary>
    Revoked = 1
}
