package org.raddatz.familienarchiv.document;

import java.util.List;
import java.util.UUID;

import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Request body for {@code PATCH /api/documents/bulk}. Field semantics:
 * <ul>
 *   <li>{@code tagNames} and {@code receiverIds} are <b>additive</b> —
 *       merged into each document's existing set, never replacing it.</li>
 *   <li>{@code senderId}, {@code documentLocation}, {@code archiveBox},
 *       {@code archiveFolder} are <b>replace-on-non-blank</b> — null/blank
 *       fields are skipped, anything else overwrites.</li>
 * </ul>
 *
 * <p>Kept as a Lombok {@code @Data} POJO (not a record) for symmetry with
 * the existing {@code DocumentUpdateDTO} and to keep test setup terse —
 * the per-feature DTOs introduced alongside this one ({@link BulkEditError},
 * {@link BulkEditResult}, {@link BatchMetadataRequest},
 * {@link DocumentBatchSummary}) <i>are</i> records because they have no
 * test-side mutation. Tracked in the cycle-1 review for follow-up.
 *
 * <p>Bean-validation caps below defend against payload-amplification: the
 * 1 MiB SvelteKit proxy cap allows ~26k UUIDs through to the backend, and
 * Jetty's default body limit is 8 MB. {@code @Size} guards catch malformed
 * clients without depending on those outer bounds.
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DocumentBulkEditDTO {

    // No @Size cap here on purpose: the controller's BULK_EDIT_MAX_IDS check
    // returns the typed BULK_EDIT_TOO_MANY_IDS error code, which the frontend
    // maps to a localised "Maximal 500 …" message via Paraglide. A bean-
    // validation @Size would short-circuit that with a generic VALIDATION_ERROR.
    private List<UUID> documentIds;

    @Size(max = 200, message = "tagNames must not exceed 200 entries")
    private List<@Size(max = 200, message = "tagName must not exceed 200 chars") String> tagNames;

    private UUID senderId;

    @Size(max = 200, message = "receiverIds must not exceed 200 entries")
    private List<UUID> receiverIds;

    @Size(max = 255, message = "documentLocation must not exceed 255 chars")
    private String documentLocation;

    @Size(max = 255, message = "archiveBox must not exceed 255 chars")
    private String archiveBox;

    @Size(max = 255, message = "archiveFolder must not exceed 255 chars")
    private String archiveFolder;
}
