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

import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import de.gecheckt.pdf.umbenenner.domain.model.DocumentFingerprint;

/**
 * Immutable summary of a {@link ResetDocumentStatusUseCase#reset(Set)} invocation.
 * <p>
 * Reports how many documents were requested for reset, which were successfully reset,
 * and which encountered a technical failure. Callers can use this record to present
 * a user-visible result or decide on follow-up actions.
 *
 * @param requestedCount    total number of fingerprints that were passed to the reset
 *                          operation; always &gt;= 0
 * @param successfullyReset set of fingerprints that were successfully deleted from
 *                          persistence; never null
 * @param failures          map of fingerprint → error message for every fingerprint
 *                          whose reset operation encountered a technical failure;
 *                          never null
 */
public record ResetDocumentStatusResult(
        int requestedCount,
        Set<DocumentFingerprint> successfullyReset,
        Map<DocumentFingerprint, String> failures) {

    /**
     * Compact constructor validating and defensively copying the mutable collections.
     *
     * @throws NullPointerException     if {@code successfullyReset} or {@code failures}
     *                                  is null
     * @throws IllegalArgumentException if {@code requestedCount} is negative
     */
    public ResetDocumentStatusResult {
        if (requestedCount < 0) {
            throw new IllegalArgumentException("requestedCount must not be negative");
        }
        Objects.requireNonNull(successfullyReset, "successfullyReset must not be null");
        Objects.requireNonNull(failures, "failures must not be null");
        successfullyReset = Collections.unmodifiableSet(Set.copyOf(successfullyReset));
        failures = Collections.unmodifiableMap(Map.copyOf(failures));
    }

    /**
     * Returns the number of fingerprints that were successfully reset.
     *
     * @return the count of successfully reset documents; always &gt;= 0
     */
    public int successCount() {
        return successfullyReset.size();
    }

    /**
     * Returns the number of fingerprints for which the reset failed with a technical error.
     *
     * @return the count of failed resets; always &gt;= 0
     */
    public int failureCount() {
        return failures.size();
    }
}
