using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Scripts;

namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Configurations;

public class SharedScriptConfiguration : IEntityTypeConfiguration<SharedScript>
{
    /// <summary>Configures the EF Core mapping for the <see cref="SharedScript"/> entity.</summary>
    /// <param name="builder">Entity type builder used to apply the configuration.</param>
    public void Configure(EntityTypeBuilder<SharedScript> builder)
    {
        builder.HasKey(s => s.Id);

        builder.Property(s => s.Name)
            .IsRequired()
            .HasMaxLength(200);

        builder.Property(s => s.Code)
            .IsRequired();

        builder.Property(s => s.ParameterDefinitions)
            .HasMaxLength(4000);

        builder.Property(s => s.ReturnDefinition)
            .HasMaxLength(4000);

        builder.HasIndex(s => s.Name).IsUnique();
    }
}
