// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

namespace Continuity.AuthServer.DB.Documents;

[Index(nameof(Username), IsUnique = true)]
[Index(nameof(Id), IsUnique = true)]
public class Account
{
    public Account(string username, byte[] password, string email, byte permissionLevel, byte[] salt)
    {
        Username = username;
        Password = password;
        Email = email;
        PermissionLevel = permissionLevel;
        Salt = salt;
    }

    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public Guid Id { get; set; }

    [MaxLength(20)] public string Username { get; set; }

    [Column(TypeName = "bytea")] public byte[] Password { get; set; }

    [EmailAddress] public string Email { get; set; }
    public byte PermissionLevel { get; set; }
    [Column(TypeName = "bytea")] public byte[] Salt { get; set; }
    public virtual ICollection<Character> Characters { get; set; }
}