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

namespace e_suite.Database.Core.Tables.Diagnostics;

[NoAudit]
[Table("PerformanceThresholds", Schema = "Diagnostics")]
public class PerformanceThreshold
{

    [Required]
    public string ControllerName { get; set; } = null!;

    [Required]
    public string ActionName { get; set; } = null!;

    [Required]
    public string RequestType { get; set; } = null!;

    [Required]
    public int TotalTimeMS { get; set; }

    public static void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<PerformanceThreshold>()
            .HasKey(x => new { x.ControllerName, x.ActionName, x.RequestType });

        modelBuilder.Entity<PerformanceThreshold>()
            .HasData(new PerformanceThreshold
                {
                    ActionName = string.Empty,
                    ControllerName = string.Empty,
                    RequestType = string.Empty,
                    TotalTimeMS = 2000
                }
            );
    }
}