using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using e_suite.Database.Audit.Attributes;
using e_suite.Database.Audit.Models;
using e_suite.Database.Core.Models;
using Microsoft.EntityFrameworkCore;

namespace e_suite.Database.Core.Tables.UserManager;

[NoAudit]
[Table("EmailUserActions", Schema = "UserManager")]
public class EmailUserAction : IId
{
    [Key]
    public long Id { get; set; }

    [Required]
    public long UserId { get; set; }

    [Required]
    public EmailUserActionType EmailActionType { get; set; }

    [Required]
    public Guid Token { get; set; }

    [Required]
    public DateTimeOffset Created { get; set; }

    [Required]
    public DateTimeOffset Expires { get; set; }

    [ForeignKey(nameof(UserId))]
    public virtual User User { get; set; } = null!;

    public static void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<EmailUserAction>().HasAlternateKey(u => new { u.Token, u.EmailActionType });
    }
}