using ERPCore.Domain.Enums;

namespace ERPCore.Domain.Entities;

/// <summary>
/// Application user (FR-X-01) — a **local shadow/projection** of an AuthHex identity.
/// The local <see cref="UserId"/> (int) is what every `createdBy`/`requestedBy`/
/// audit/ledger FK references; <see cref="AuthUserId"/> maps it to the AuthHex
/// <c>UserId</c> (GUID) and is JIT-provisioned on first authenticated request
/// (docs/10 A.4/C.7). A seeded <c>system</c> user (id 1, null AuthUserId) is the
/// fallback actor for unauthenticated/system operations. Model: docs/10 Part C.7.
/// </summary>
public class User
{
    /// <summary>Seeded fallback actor for unauthenticated/system operations.</summary>
    public const int SystemUserId = 1;

    public int UserId { get; set; }
    public string Username { get; set; } = string.Empty;
    public string DisplayName { get; set; } = string.Empty;
    public EntityStatus Status { get; set; } = EntityStatus.Active;

    /// <summary>AuthHex identity (token <c>UserId</c> GUID); null for the seeded system user.</summary>
    public Guid? AuthUserId { get; set; }

    /// <summary>
    /// Mirrors the AuthHex identity's email (backfilled at create time by
    /// <c>UsersController.Create</c>, best-effort by JIT provisioning otherwise).
    /// Used only for the Employee&lt;-&gt;User cross-link soft match (docs/12-BACKEND-HRM.md
    /// A.5) — never for authentication, which stays AuthHex's responsibility.
    /// </summary>
    public string? Email { get; set; }

    /// <summary>Local shadow <see cref="Role"/> assignment; null until an admin assigns one.</summary>
    public int? RoleId { get; set; }
    public Role? Role { get; set; }
}
