using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using ScadaLink.Commons.Entities.Scripts;

namespace ScadaLink.ConfigurationDatabase.Configurations;

public class SharedScriptConfiguration : IEntityTypeConfiguration<SharedScript>
{
    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();
    }
}
