using AdsManagerService.Domain.AggregatesModel.AdAggregate;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace AdsManagerService.Infrastructure.EntityConfigurations;

public class AdEntityTypeConfiguration : IEntityTypeConfiguration<Ad>
{
    public void Configure(EntityTypeBuilder<Ad> builder)
    {
        builder.ToTable("ads");

        builder.HasKey(a => a.Id);

        builder.Property(a => a.Id).HasColumnName("id").IsRequired();
        builder.Property(a => a.AdSetId).HasColumnName("ad_set_id").IsRequired();
        builder.Property(a => a.Name).HasColumnName("name").HasMaxLength(255).IsRequired();
        builder.Property(a => a.FormatId).HasColumnName("format_id").IsRequired();
        builder.Property(a => a.StatusId).HasColumnName("status_id").IsRequired();
        builder.Property(a => a.ReviewStatusId).HasColumnName("review_status_id").IsRequired();

        builder.Property(a => a.Headline).HasColumnName("headline").HasMaxLength(255);
        builder.Property(a => a.PrimaryText).HasColumnName("primary_text").HasMaxLength(1000);
        builder.Property(a => a.Description).HasColumnName("description").HasMaxLength(500);
        builder.Property(a => a.CallToAction).HasColumnName("call_to_action").HasMaxLength(50);
        builder.Property(a => a.DestinationUrl).HasColumnName("destination_url").HasMaxLength(2048);
        builder.Property(a => a.CreativeUrl).HasColumnName("creative_url").HasMaxLength(2048);

        builder.Property(a => a.CreatedAt).HasColumnName("created_at").IsRequired();
        builder.Property(a => a.UpdatedAt).HasColumnName("updated_at");

        // Indexes
        builder.HasIndex(a => a.AdSetId).HasDatabaseName("idx_ads_ad_set_id");
        builder.HasIndex(a => a.StatusId).HasDatabaseName("idx_ads_status_id");
        builder.HasIndex(a => a.ReviewStatusId).HasDatabaseName("idx_ads_review_status_id");

        builder.Ignore(a => a.DomainEvents);
        builder.Ignore(a => a.Format);
        builder.Ignore(a => a.Status);
        builder.Ignore(a => a.ReviewStatus);
    }
}
