using System.Text.Json.Serialization;

namespace Managing.Infrastructure.Evm.Models.Privy
{
    /// <summary>
    /// Represents user information returned from the Privy API
    /// </summary>
    public class PrivyUserInfo
    {
        [JsonPropertyName("did")]
        public string Did { get; set; }
        
        [JsonPropertyName("linked_accounts")]
        public List<PrivyLinkedAccount> LinkedAccounts { get; set; } = new List<PrivyLinkedAccount>();
        
        // These fields might be optional in the response
        [JsonPropertyName("created_at")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public long? CreatedAtTimestamp { get; set; }
        
        [JsonPropertyName("updated_at")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public long? UpdatedAtTimestamp { get; set; }
        
        // Computed properties to convert Unix timestamps to DateTime
        [JsonIgnore]
        public DateTime? CreatedAt => CreatedAtTimestamp.HasValue 
            ? DateTimeOffset.FromUnixTimeSeconds(CreatedAtTimestamp.Value).DateTime 
            : null;
            
        [JsonIgnore]
        public DateTime? UpdatedAt => UpdatedAtTimestamp.HasValue 
            ? DateTimeOffset.FromUnixTimeSeconds(UpdatedAtTimestamp.Value).DateTime 
            : null;
    }
    
    /// <summary>
    /// Represents a linked account in the Privy user's profile
    /// </summary>
    public class PrivyLinkedAccount
    {
        [JsonPropertyName("type")]
        public string Type { get; set; }
        
        [JsonPropertyName("address")]
        public string Address { get; set; }
        
        [JsonPropertyName("chain_type")]
        public string ChainType { get; set; }
        
        [JsonPropertyName("delegated")]
        public bool Delegated { get; set; }
        
        [JsonPropertyName("verified")]
        public bool? Verified { get; set; }
        
        // Additional fields from the actual response
        [JsonPropertyName("wallet_index")]
        public int? WalletIndex { get; set; }
        
        [JsonPropertyName("wallet_client")]
        public string WalletClient { get; set; }
        
        [JsonPropertyName("wallet_client_type")]
        public string WalletClientType { get; set; }
        
        [JsonPropertyName("connector_type")]
        public string ConnectorType { get; set; }
        
        [JsonPropertyName("imported")]
        public bool? Imported { get; set; }
        
        [JsonPropertyName("recovery_method")]
        public string RecoveryMethod { get; set; }
        
        [JsonPropertyName("chain_id")]
        public string ChainId { get; set; }
        
        [JsonPropertyName("id")]
        public string Id { get; set; }
        
        [JsonPropertyName("verified_at")]
        public long? VerifiedAtTimestamp { get; set; }
        
        [JsonPropertyName("first_verified_at")]
        public long? FirstVerifiedAtTimestamp { get; set; }
        
        [JsonPropertyName("latest_verified_at")]
        public long? LatestVerifiedAtTimestamp { get; set; }
        
        // Computed properties to convert Unix timestamps to DateTime
        [JsonIgnore]
        public DateTime? VerifiedAt => VerifiedAtTimestamp.HasValue 
            ? DateTimeOffset.FromUnixTimeSeconds(VerifiedAtTimestamp.Value).DateTime 
            : null;
            
        [JsonIgnore]
        public DateTime? FirstVerifiedAt => FirstVerifiedAtTimestamp.HasValue 
            ? DateTimeOffset.FromUnixTimeSeconds(FirstVerifiedAtTimestamp.Value).DateTime 
            : null;
            
        [JsonIgnore]
        public DateTime? LatestVerifiedAt => LatestVerifiedAtTimestamp.HasValue 
            ? DateTimeOffset.FromUnixTimeSeconds(LatestVerifiedAtTimestamp.Value).DateTime 
            : null;
    }
} 