using System.ComponentModel.DataAnnotations;
using ERPCore.Domain.Enums;

namespace ERPCore.Dtos.Users;

public sealed record ManagedUserDto(
    int UserId, string Username, string DisplayName, string? Email, EntityStatus Status,
    int? RoleId, string? RoleCode, string? RoleName);

/// <summary>
/// Creates a user in both backends: forwards to AuthHex's `registerUser` (source
/// of truth for credentials), then mirrors the account into ERPCore's local
/// shadow `User` row immediately (rather than waiting for next-login JIT
/// provisioning). AuthHex emails the generated/supplied password to `Email`.
/// </summary>
public sealed class CreateUserRequest
{
    [Required, StringLength(100)] public string Username { get; set; } = string.Empty;
    [Required, StringLength(200)] public string FullName { get; set; } = string.Empty;
    [Required] public int RoleId { get; set; }
    [Required] public Guid UserTypeId { get; set; }
    [Required, EmailAddress] public string Email { get; set; } = string.Empty;
    public string? Nic { get; set; }
    public string? MobileNumber { get; set; }
    /// <summary>Left empty to auto-generate (AuthHex emails it to <see cref="Email"/>).</summary>
    public string? Password { get; set; }

    /// <summary>
    /// Explicit, human-confirmed link to an existing unlinked Employee found via
    /// email-lookup — never automatic, even on an exact email match (docs/12-BACKEND-HRM.md A.5).
    /// </summary>
    public int? LinkEmployeeId { get; set; }
}

public sealed class UpdateUserRoleRequest
{
    [Required] public int RoleId { get; set; }
}

/// <summary>AuthHex UserType lookup, for populating the create-user form's select (no local shadow — read-only passthrough).</summary>
public sealed record UserTypeOptionDto(Guid UserTypeId, string? Code, string? Description);
