using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using UniVerse.Domain.Entities;

namespace UniVerse.Infrastructure.Data.Configurations;

public class LevelThresholdConfiguration : IEntityTypeConfiguration<LevelThreshold>
{
    public void Configure(EntityTypeBuilder<LevelThreshold> builder)
    {
        builder.ToTable("level_thresholds", table =>
        {
            table.HasCheckConstraint("CK_level_thresholds_level_positive", "level > 0");
            table.HasCheckConstraint("CK_level_thresholds_required_xp_non_negative", "required_xp >= 0");
        });

        builder.HasKey(t => t.Level);
        builder.Property(t => t.Level).HasColumnName("level").ValueGeneratedNever();
        builder.Property(t => t.RequiredXp).HasColumnName("required_xp").IsRequired();
        builder.HasIndex(t => t.RequiredXp).IsUnique();

        builder.HasData(
            new LevelThreshold { Level = 1, RequiredXp = 0 },
            new LevelThreshold { Level = 2, RequiredXp = 100 },
            new LevelThreshold { Level = 3, RequiredXp = 300 },
            new LevelThreshold { Level = 4, RequiredXp = 600 },
            new LevelThreshold { Level = 5, RequiredXp = 1000 },
            new LevelThreshold { Level = 6, RequiredXp = 1500 },
            new LevelThreshold { Level = 7, RequiredXp = 2500 },
            new LevelThreshold { Level = 8, RequiredXp = 4000 }
        );
    }
}
