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

namespace ScadaLink.ConfigurationDatabase.Configurations;

public class ApiKeyConfiguration : IEntityTypeConfiguration<ApiKey>
{
    public void Configure(EntityTypeBuilder<ApiKey> builder)
    {
        builder.HasKey(k => k.Id);

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

        builder.Property(k => k.KeyValue)
            .IsRequired()
            .HasMaxLength(500);

        builder.HasIndex(k => k.Name).IsUnique();
        builder.HasIndex(k => k.KeyValue).IsUnique();
    }
}

public class ApiMethodConfiguration : IEntityTypeConfiguration<ApiMethod>
{
    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.ApprovedApiKeyIds)
            .HasMaxLength(4000);

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

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

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