using Indotalent.Data.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Indotalent.Infrastructure.Database.MsSQL.Configuration;

public class LogConfiguration : IEntityTypeConfiguration<SerilogLogs>
{
    public void Configure(EntityTypeBuilder<SerilogLogs> builder)
    {
        builder.ToTable("SerilogLogs");

        builder.HasKey(e => e.Id);

        builder.Property(e => e.Message)
            .HasMaxLength(2000);

        builder.Property(e => e.Level)
            .HasMaxLength(128);

        builder.Property(e => e.TimeStamp)
            .IsRequired();

        builder.Property(e => e.Exception)
            .HasColumnType("nvarchar(max)");

        builder.Property(e => e.Properties)
            .HasColumnType("nvarchar(max)");

        builder.Property(e => e.MessageTemplate)
            .HasMaxLength(2000);

        builder.Property(e => e.LogEvent)
            .HasColumnType("nvarchar(max)");

        builder.HasIndex(e => e.TimeStamp)
               .HasDatabaseName("IX_SerilogLogs_TimeStamp");
    }
}