package de.gecheckt.pdf.umbenenner.domain.model;

import java.io.Serializable;
import java.util.Objects;

/**
 * Unique identifier for a batch run.
 * <p>
 * Each invocation of the PDF Umbenenner application receives a unique RunId
 * that persists for the entire batch processing cycle. The RunId is used to:
 * <ul>
 *   <li>Correlate all documents processed in a single run</li>
 *   <li>Track attempt history and retry decisions across runs</li>
 *   <li>Identify logs and audit trails for a specific execution</li>
 * </ul>
 * <p>
 * RunId is intentionally simple: a non-null, immutable string value.
 * Implementations may choose UUID format, timestamp-based IDs, or sequential IDs.
 * The internal structure is opaque to consumers.
 */
public final class RunId implements Serializable {

    private static final long serialVersionUID = 1L;

    private final String value;

    /**
     * Creates a new RunId with the given string value.
     * <p>
     * The value must be non-null and non-empty. No format validation is enforced;
     * implementations are free to choose their own ID scheme.
     *
     * @param value the unique identifier string, must not be null or empty
     * @throws NullPointerException if value is null
     * @throws IllegalArgumentException if value is empty
     */
    public RunId(String value) {
        Objects.requireNonNull(value, "RunId value must not be null");
        if (value.trim().isEmpty()) {
            throw new IllegalArgumentException("RunId value must not be empty");
        }
        this.value = value;
    }

    /**
     * Returns the string representation of this RunId.
     *
     * @return the unique identifier value
     */
    public String value() {
        return value;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RunId runId = (RunId) o;
        return Objects.equals(value, runId.value);
    }

    @Override
    public int hashCode() {
        return Objects.hash(value);
    }

    @Override
    public String toString() {
        return value;
    }
}
