package at.procon.dip.ingestion.spi;

import at.procon.dip.domain.access.DocumentAccessContext;
import at.procon.dip.domain.document.SourceType;
import java.time.OffsetDateTime;
import java.util.Map;

/**
 * Describes a source object that should be ingested into the canonical document model.
 * <p>
 * Phase 4 extends the descriptor with optional inline payload fields so adapters can support
 * both file-backed imports and direct upload/API ingestion without introducing separate DTO trees.
 */
public record SourceDescriptor(
        DocumentAccessContext accessContext,
        SourceType sourceType,
        String sourceIdentifier,
        String sourceUri,
        String fileName,
        String mediaType,
        byte[] binaryContent,
        String textContent,
        OffsetDateTime receivedAt,
        OriginalContentStoragePolicy originalContentStoragePolicy,
        Map<String, String> attributes
) {

    public SourceDescriptor {
        if (originalContentStoragePolicy == null) {
            originalContentStoragePolicy = OriginalContentStoragePolicy.DEFAULT;
        }
    }

    public boolean hasInlineBinaryContent() {
        return binaryContent != null && binaryContent.length > 0;
    }

    public boolean hasInlineTextContent() {
        return textContent != null && !textContent.isBlank();
    }
}
