using Domain.Entities.Common; using Domain.Entities.Common.ValueObject; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Infrastructure.Persistence.Configurations.Common; public sealed class EmailLogConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ToTable(nameof(EmailLog), x => x.HasComment("이메일 발송 큐")); builder.HasKey(x => x.ID); builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK"); builder.Property(x => x.ToAddress).IsRequired().HasMaxLength(256).HasComment("수신자 이메일"); builder.Property(x => x.Subject).IsRequired().HasMaxLength(500).HasComment("제목"); builder.Property(x => x.MessageHtml).IsRequired().HasComment("HTML 본문"); builder.Property(x => x.MessageText).HasComment("텍스트 본문 (선택)"); builder.Property(x => x.Status).IsRequired().HasDefaultValue(MailStatus.Pending).HasComment("상태 (0=Pending, 1=Processing, 2=Sent, 3=Failed)"); builder.Property(x => x.RetryCount).IsRequired().HasDefaultValue(0).HasComment("재시도 횟수"); builder.Property(x => x.MaxRetryCount).IsRequired().HasDefaultValue(3).HasComment("최대 재시도 횟수"); builder.Property(x => x.NextRetryAt).IsRequired().HasDefaultValueSql("GETUTCDATE()").HasComment("다음 시도 시각 (UTC)"); builder.Property(x => x.LastError).HasMaxLength(500).HasComment("마지막 오류 메시지"); builder.Property(x => x.Category).HasMaxLength(50).HasComment("카테고리 (auth.register, forum.post.notify 등)"); builder.Property(x => x.CreatedAt).IsRequired().HasDefaultValueSql("GETUTCDATE()").HasComment("등록 시각 (UTC)"); builder.Property(x => x.ProcessedAt).HasComment("처리 완료 시각 (UTC)"); builder.Property(x => x.FailedAt).HasComment("실패 확정 시각 (UTC)"); builder.HasIndex(x => new { x.Status, x.NextRetryAt }).HasDatabaseName("IX_EmailLog_Status_NextRetryAt"); builder.HasIndex(x => x.CreatedAt).HasDatabaseName("IX_EmailLog_CreatedAt"); } }