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

namespace OmsorgCore.Infrastructure.Persistence.Configurations;

public class LoginAttemptConfiguration : IEntityTypeConfiguration<LoginAttempt>
{
    public void Configure(EntityTypeBuilder<LoginAttempt> builder)
    {
        builder.ToTable("login_attempts");
        builder.HasKey(a => a.Id);
        builder.Property(a => a.IpAddress).IsRequired().HasMaxLength(64);
        builder.Property(a => a.Username).IsRequired().HasMaxLength(100);
        builder.HasIndex(a => new { a.IpAddress, a.AttemptedAt });
    }
}
