using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SolutionErp.Domain.Office;

namespace SolutionErp.Infrastructure.Persistence.Configurations;

// EF Mig 38 G-O3 (S37) — Attachment cho Đề xuất.
// FK Cascade Proposal (wipe khi xoá Đề xuất).
public class ProposalAttachmentConfiguration : IEntityTypeConfiguration<ProposalAttachment>
{
    public void Configure(EntityTypeBuilder<ProposalAttachment> e)
    {
        e.ToTable("ProposalAttachments");

        e.Property(x => x.FileName).HasMaxLength(500).IsRequired();
        e.Property(x => x.FilePath).HasMaxLength(1000).IsRequired();
        e.Property(x => x.MimeType).HasMaxLength(200);
        e.Property(x => x.UploadedByFullName).HasMaxLength(200).IsRequired();

        e.HasOne(x => x.Proposal)
            .WithMany(p => p.Attachments)
            .HasForeignKey(x => x.ProposalId)
            .OnDelete(DeleteBehavior.Cascade);

        e.HasIndex(x => x.ProposalId);
    }
}
