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

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

// The SQL Server ApiKey entity was retired — inbound API keys now
// live in the shared ZB.MOM.WW.Auth.ApiKeys SQLite store. The former
// ApiKeyConfiguration (and the ApiMethod.ApprovedApiKeyIds mapping) were removed; the
// ApiKeys table + ApprovedApiKeyIds column are dropped by the RetireInboundApiKeyStore
// migration.

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

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

        builder.Property(m => m.Script)
            .IsRequired();

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

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

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