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

namespace e_suite.Database.Core.Tables.Domain;

[DisplayName("RoleAccess")]
[Table("RoleAccess", Schema = "Domain")]
public class RoleAccess
{
    [Required]
    public long RoleId { get; set; }

    /// <summary>
    /// Contains the Enum value for the security access entry
    /// </summary>
    [Required]
    public int AccessKey { get; set; }

    [AuditLastUpdated]
    public DateTimeOffset LastUpdated { get; set; }

    [AuditParent]
    [ForeignKey(nameof(RoleId))]
    public virtual Role Role { get; set; } = null!;

    public static void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<RoleAccess>()
            .HasKey(gc => new { gc.RoleId, gc.AccessKey });
    }
}