using ClaudeDo.Data.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace ClaudeDo.Data.Configuration;

public class ListEntityConfiguration : IEntityTypeConfiguration<ListEntity>
{
    public void Configure(EntityTypeBuilder<ListEntity> builder)
    {
        builder.ToTable("lists");

        builder.HasKey(l => l.Id);
        builder.Property(l => l.Id).HasColumnName("id");
        builder.Property(l => l.Name).HasColumnName("name").IsRequired();
        builder.Property(l => l.CreatedAt).HasColumnName("created_at").IsRequired();
        builder.Property(l => l.WorkingDir).HasColumnName("working_dir");
        builder.Property(l => l.DefaultCommitType).HasColumnName("default_commit_type").IsRequired().HasDefaultValue("chore");
        builder.Property(l => l.SortOrder).HasColumnName("sort_order").IsRequired().HasDefaultValue(0);
        builder.Property(l => l.IsManual).HasColumnName("is_manual").IsRequired().HasDefaultValue(false);
        builder.Property(l => l.FindingsTracked).HasColumnName("findings_tracked").IsRequired().HasDefaultValue(false);
        builder.Property(l => l.Icon).HasColumnName("icon");

        builder.HasIndex(l => l.SortOrder).HasDatabaseName("idx_lists_sort");

        builder.HasOne(l => l.Config)
            .WithOne(c => c.List)
            .HasForeignKey<ListConfigEntity>(c => c.ListId)
            .OnDelete(DeleteBehavior.Cascade);
    }
}
