using System.ComponentModel.DataAnnotations;

namespace WishNinja.Data.Entities;

/// <summary>
/// An admin-issued invitation. The raw token is emailed to the recipient; only its hash is stored.
/// Single-use: <see cref="AcceptedAt"/> is set once redeemed.
/// </summary>
public class Invite
{
    public int Id { get; set; }

    [Required, MaxLength(256)]
    public string Email { get; set; } = string.Empty;

    /// <summary>SHA-256 hash (Base64) of the raw token. The raw token is never persisted.</summary>
    [Required, MaxLength(64)]
    public string TokenHash { get; set; } = string.Empty;

    /// <summary>Identity role granted on acceptance (e.g. "User" or "Admin").</summary>
    [Required, MaxLength(64)]
    public string Role { get; set; } = "User";

    public string InvitedByUserId { get; set; } = string.Empty;
    public ApplicationUser? InvitedByUser { get; set; }

    public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
    public DateTimeOffset ExpiresAt { get; set; }
    public DateTimeOffset? AcceptedAt { get; set; }

    public bool IsAccepted => AcceptedAt is not null;
}
