using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using FacebookService.Domain.AggregatesModel.ChatbotAggregate;

namespace FacebookService.Infrastructure.EntityConfigurations;

/// <summary>
/// EN: EF Core configuration for AIChatbotConfig entity.
/// VI: Cấu hình EF Core cho entity AIChatbotConfig.
/// </summary>
public class AIChatbotConfigEntityTypeConfiguration : IEntityTypeConfiguration<AIChatbotConfig>
{
    public void Configure(EntityTypeBuilder<AIChatbotConfig> builder)
    {
        // EN: Table name / VI: Tên bảng
        builder.ToTable("ai_chatbot_configs");

        // EN: Primary key / VI: Khóa chính
        builder.HasKey(c => c.Id);

        // EN: Ignore domain events / VI: Bỏ qua domain events
        builder.Ignore(c => c.DomainEvents);

        // EN: Properties / VI: Các thuộc tính
        builder.Property(c => c.Id)
            .HasColumnName("id")
            .IsRequired();

        builder.Property<Guid>("_shopId")
            .HasColumnName("shop_id")
            .IsRequired();

        builder.Property(c => c.ProviderId)
            .HasColumnName("provider_id")
            .IsRequired();

        builder.Property<string>("_model")
            .HasColumnName("model")
            .HasMaxLength(50)
            .IsRequired();

        builder.Property<string>("_systemPrompt")
            .HasColumnName("system_prompt")
            .IsRequired();

        builder.Property<float>("_temperature")
            .HasColumnName("temperature")
            .IsRequired();

        builder.Property<int>("_maxTokens")
            .HasColumnName("max_tokens")
            .IsRequired();

        builder.Property<bool>("_isEnabled")
            .HasColumnName("is_enabled")
            .IsRequired();

        builder.Property<DateTime>("_createdAt")
            .HasColumnName("created_at")
            .IsRequired();

        builder.Property<DateTime>("_updatedAt")
            .HasColumnName("updated_at")
            .IsRequired();

        // EN: Provider navigation / VI: Navigation cho provider
        builder.HasOne(c => c.Provider)
            .WithMany()
            .HasForeignKey(c => c.ProviderId)
            .OnDelete(DeleteBehavior.Restrict);

        // EN: Indexes / VI: Các index
        builder.HasIndex("_shopId")
            .IsUnique()
            .HasDatabaseName("idx_ai_configs_shop_id");
    }
}
