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

namespace Infrastructure.Persistence.Configurations.Director;

public sealed class AdminLoginLogConfiguration : IEntityTypeConfiguration<AdminLoginLog>
{
    public void Configure(EntityTypeBuilder<AdminLoginLog> builder)
    {
        builder.HasIndex(x => x.Account);
        builder.HasIndex(x => x.CreatedAt);

        builder.ToTable(nameof(AdminLoginLog), x => x.HasComment("관리자 로그인 기록"));
        builder.HasKey(x => x.ID);
        builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
        builder.Property(x => x.Success).IsRequired().HasComment("로그인 성공 여부");
        builder.Property(x => x.Account).HasMaxLength(120).IsRequired().HasComment("로그인 시도 계정");
        builder.Property(x => x.Reason).HasMaxLength(225).HasComment("실패 사유");
        builder.Property(x => x.IpAddress).HasMaxLength(45).HasComment("IP 주소");
        builder.Property(x => x.UserAgent).HasMaxLength(512).HasComment("User Agent");
        builder.Property(x => x.CreatedAt).IsRequired().HasComment("생성 일시");
    }
}