#nullable enable
using Baya.Domain.Common;

namespace Baya.Domain.Entities.Messaging;

/// <summary>
/// One message on a ticket thread. <see cref="IsInternal"/> is the <b>hard visibility boundary</b>: an
/// admin-only internal note that must never appear in any user-facing query, payload, or join — a non-admin can
/// neither set nor read it. This is enforced in the query projection (the user view of a thread strips every
/// internal message), not in the UI.
/// </summary>
public class TicketMessage : BaseEntity<long>
{
    public long TicketId { get; set; }
    public Ticket Ticket { get; set; } = null!;

    /// <summary>The <c>users.id</c> that sent the message.</summary>
    public int SenderId { get; set; }

    public string Body { get; set; } = string.Empty;

    /// <summary>Admin-only note. Default <c>false</c>. The hard visibility boundary — stripped from every
    /// user-facing thread read; only the admin view returns it.</summary>
    public bool IsInternal { get; set; }

    /// <summary>Optional client-generated idempotency key for the optimistic composer — a retried send (network
    /// flap) carrying the same key is deduplicated rather than posted twice. Unique per ticket when present.</summary>
    public string? ClientMessageId { get; set; }

    public DateTimeOffset SentAt { get; set; }

    public DateTimeOffset? DeletedAt { get; set; }
}
