using Ablera.Serdica.Extensions.Novell.Directory.Ldap.Attributes;
using Ablera.Serdica.Extensions.Novell.Directory.Ldap.Contracts;
using Ablera.Serdica.Extensions.Novell.Directory.Ldap.Models;
using Microsoft.AspNetCore.Identity;

namespace Ablera.Serdica.Authority.Plugin.Ldap.Models;

/// <summary>
/// Strongly‑typed projection of a Bulstrad AD user entry.
/// </summary>
public class BulstradAdIdentity : ILdapIdentity<string>
{
    /* ────────────────────────── Core identification ────────────────────────── */
    [LdapProperty("sAMAccountName")]
    public required string Username { get; set; }

    [LdapProperty("userPrincipalName")]
    public string? Email { get; set; }

    [LdapProperty("cn")]
    public string? CommonName { get; set; }

    [LdapProperty("givenName")]
    public string? GivenName { get; set; }

    [LdapProperty("sn")]
    public string? Surname { get; set; }

    /* ────────────────────────── Human‑readable info ────────────────────────── */
    [LdapProperty("displayName")]
    public string? DisplayName { get; set; }

    [LdapProperty("description")]
    public string? Description { get; set; }

    [LdapProperty("info")]
    public string? Info { get; set; }                 // free‑form notes

    /* ────────────────────────── DN & object identity ───────────────────────── */
    public string? DistinguishedName { get; set; }  // NOTE: This is populated by the Novel.LdapEntry.DN
    /// </summary>

    [LdapProperty("objectClass")]
    public string[]? ObjectClasses { get; set; }      // multivalued

    [LdapProperty("objectGUID")]
    public Guid? ObjectGuid { get; set; }

    [LdapProperty("objectSid")]
    public string? ObjectSid { get; set; }

    [LdapProperty("objectCategory")]
    public string? ObjectCategory { get; set; }

    /* ────────────────────────── Group memberships ──────────────────────────── */
    [LdapProperty("memberOf")]
    public string[]? MemberOf { get; set; }

    [LdapProperty("primaryGroupID")]
    public int? PrimaryGroupId { get; set; }

    /* ────────────────────────── Account state & counters ───────────────────── */
    [LdapProperty("userAccountControl")]
    public int? UserAccountControl { get; set; }

    [LdapProperty("accountExpires")]
    public long? AccountExpires { get; set; }

    [LdapProperty("lockoutTime")]
    public long? LockoutTime { get; set; }

    [LdapProperty("badPwdCount")]
    public int? BadPasswordCount { get; set; }

    [LdapProperty("logonCount")]
    public int? LogonCount { get; set; }

    [LdapProperty("pwdLastSet")]
    public long? PwdLastSet { get; set; }

    [LdapProperty("lastLogon")]
    public long? LastLogon { get; set; }

    [LdapProperty("lastLogonTimestamp")]
    public long? LastLogonTimestamp { get; set; }

    [LdapProperty("lastLogoff")]
    public long? LastLogoff { get; set; }

    /* ────────────────────────── Audit / replication ────────────────────────── */
    [LdapProperty("whenCreated")]
    public DateTime? WhenCreated { get; set; }

    [LdapProperty("whenChanged")]
    public DateTime? WhenChanged { get; set; }

    [LdapProperty("uSNCreated")]
    public long? UsnCreated { get; set; }

    [LdapProperty("uSNChanged")]
    public long? UsnChanged { get; set; }

    [LdapProperty("dSCorePropagationData")]
    public string[]? DsCorePropagationData { get; set; }

    /* ────────────────────────── Misc technical fields ──────────────────────── */
    [LdapProperty("instanceType")]
    public int? InstanceType { get; set; }

    [LdapProperty("protocolSettings")]
    public string[]? ProtocolSettings { get; set; }

    [LdapProperty("msDS-SupportedEncryptionTypes")]
    public int? SupportedEncryptionTypes { get; set; }

    /* ────────────────────────── Infrastructure hooks ───────────────────────── */
    public required IdentityUser<string> Identity { get; set; }
    public required LdapSettings LdapSettings { get; set; }
}

