using Butter.Types;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

namespace Lactose.Models;

/// <summary>
/// Represents a user in the system.
/// </summary>
public class User {
    /// <summary>
    /// Gets or sets the unique identifier for the user.
    /// </summary>
    [Key]
    public Guid Id { get; set; }

    /// <summary>
    /// Gets or sets the username of the user.
    /// </summary>
    [Column(TypeName = "VARCHAR(64)")]
    public string Username { get; set; } = string.Empty;

    /// <summary>
    /// Gets or sets the email address of the user.
    /// </summary>
    [Column(TypeName = "VARCHAR(128)")]
    public string Email { get; set; } = string.Empty;

    /// <summary>
    /// Gets or sets the password of the user.
    /// </summary>
    [Column(TypeName = "VARCHAR(255)")][JsonIgnore]
    public string Password { get; set; } = string.Empty;

    /// <summary>
    /// Gets or sets the date and time when the user was created.
    /// </summary>
    [Required]
    public DateTime CreatedAt { get; set; } = DateTime.Now;

    /// <summary>
    /// Gets or sets the date and time when the user was last updated.
    /// </summary>
    public DateTime? UpdatedAt { get; set; }

    /// <summary>
    /// Gets or sets the date and time when the user last logged in.
    /// </summary>
    public DateTime? LastLogin { get; set; }

    /// <summary>
    /// Gets or sets the date and time when the user was banned.
    /// </summary>
    public DateTime? BannedAt  { get; set; }

    /// <summary>
    /// Gets or sets the date and time when the user was deleted.
    /// </summary>
    public DateTime? DeletedAt { get; set; }

    /// <summary>
    /// Gets or sets the access level of the user.
    /// </summary>
    public EAccessLevel AccessLevel { get; set; }
    
    [Column(TypeName = "VARCHAR(255)")][JsonIgnore]
    public string RefreshToken { get; set; } = string.Empty;
    
    public DateTime? RefreshTokenExpires { get; set; }

#region Navigation Properties

    /// <summary>
    /// Gets or sets the list of assets owned by the user.
    /// </summary>
    public List<Asset>? OwnedAssets { get; set; }

    /// <summary>
    /// Gets or sets the list of albums owned by the user.
    /// </summary>
    public List<Album>? OwnedAlbums { get; set; }

#endregion
}
