Files
DocumentService/DocumentOperator.Application/Common/DTOs/AttachmentInfo.cs
TekH d123bc996e refactor: Move DTOs from Domain to Application layer
- Move PdfMetadata, PdfAMetadata from Domain.Models.ValueObjects to Application.Common.DTOs
- Move AttachmentInfo, AttachmentMetadata from Domain.Models.ValueObjects to Application.Common.DTOs
- Reason: DTOs belong in Application layer, Domain should have zero external dependencies (Clean Architecture)
2026-07-20 11:55:01 +02:00

61 lines
2.1 KiB
C#

namespace DocumentOperator.Application.Common.DTOs;
/// <summary>
/// Represents complete attachment information for a PDF document.
/// Immutable value object containing attachment presence flag, count, and detailed metadata.
/// </summary>
public sealed class AttachmentInfo
{
/// <summary>
/// Gets a value indicating whether the PDF contains any attachments
/// </summary>
public bool HasAttachments { get; }
/// <summary>
/// Gets the total number of attachments in the PDF
/// </summary>
public int AttachmentCount { get; }
/// <summary>
/// Gets the collection of attachment metadata (file details)
/// </summary>
public IReadOnlyList<AttachmentMetadata> Attachments { get; }
/// <summary>
/// Initializes a new instance of the AttachmentInfo class.
/// </summary>
/// <param name="hasAttachments">Whether PDF has attachments</param>
/// <param name="attachmentCount">Total number of attachments</param>
/// <param name="attachments">List of attachment metadata (can be empty)</param>
public AttachmentInfo(bool hasAttachments, int attachmentCount, IReadOnlyList<AttachmentMetadata> attachments)
{
HasAttachments = hasAttachments;
AttachmentCount = attachmentCount;
Attachments = attachments ?? [];
// Defensive Programming: Ensure count matches list length
if (Attachments.Count != attachmentCount)
{
throw new ArgumentException(
$"Attachment count mismatch: expected {attachmentCount}, got {Attachments.Count}",
nameof(attachments));
}
}
/// <summary>
/// Creates an AttachmentInfo instance for a PDF with no attachments.
/// </summary>
public static AttachmentInfo Empty =>
new(
hasAttachments: false,
attachmentCount: 0,
attachments: []);
public override string ToString()
{
return HasAttachments
? $"PDF has {AttachmentCount} attachment(s): {string.Join(", ", Attachments.Select(a => a.FileName))}"
: "PDF has no attachments";
}
}