package de.gecheckt.pdf.umbenenner.application.port.out;

import java.util.Objects;

/**
 * Technical failure during fingerprint computation.
 * <p>
 * Returned by {@link FingerprintPort} when the adapter cannot read the file content
 * to compute the SHA-256 hash. Typical causes include the file no longer being
 * accessible between candidate discovery and hashing, I/O errors, or permission issues.
 * <p>
 * <strong>Historisation impact:</strong> Because no {@link de.gecheckt.pdf.umbenenner.domain.model.DocumentFingerprint}
 * could be produced, this failure is <em>not</em> historised in SQLite. No
 * {@link ProcessingAttempt} is created.
 *
 * @param errorMessage human-readable description of the failure; never null or blank
 * @param cause        the underlying throwable, or {@code null} if not available
 */
public record FingerprintTechnicalError(String errorMessage, Throwable cause) implements FingerprintResult {

    /**
     * Compact constructor validating the error message.
     *
     * @throws NullPointerException     if {@code errorMessage} is null
     * @throws IllegalArgumentException if {@code errorMessage} is blank
     */
    public FingerprintTechnicalError {
        Objects.requireNonNull(errorMessage, "errorMessage must not be null");
        if (errorMessage.isBlank()) {
            throw new IllegalArgumentException("errorMessage must not be blank");
        }
    }
}
