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

namespace Indotalent.Infrastructure.Database.MsSQL.Configuration;

public class AutoNumberSequenceConfiguration : IEntityTypeConfiguration<AutoNumberSequence>
{
    public void Configure(EntityTypeBuilder<AutoNumberSequence> builder)
    {

        builder.Property(e => e.EntityName)
            .HasMaxLength(GlobalConsts.StringLengthShort);

        builder.Property(e => e.PrefixTemplate)
            .HasMaxLength(GlobalConsts.StringLengthShort);

        builder.Property(e => e.SuffixTemplate)
            .HasMaxLength(GlobalConsts.StringLengthShort);

        builder.HasIndex(e => new { e.TenantId, e.EntityName, e.Year, e.Month })
            .IsUnique();
    }
}