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

import java.util.Objects;

/**
 * Lookup result indicating that the master record lookup itself failed due to a
 * technical infrastructure problem.
 * <p>
 * The persistence layer (SQLite) could not be reached or returned an unexpected error.
 * The document state is unknown; the use case must treat this candidate as a
 * transient technical failure for this run and must not attempt to write any attempt
 * record (since the underlying persistence is unavailable).
 * <p>
 * This variant is distinct from a business-level "document not found" outcome
 * ({@link DocumentUnknown}): here, the lookup operation itself failed.
 *
 * @param errorMessage human-readable description of the persistence failure; never null or blank
 * @param cause        the underlying throwable, or {@code null} if not available
 */
public record PersistenceLookupTechnicalFailure(String errorMessage, Throwable cause)
        implements DocumentRecordLookupResult {

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