package dev.photosync.core.config;

import lombok.Builder;

/** How aggressively the queue drains, and what happens when the player quits. */
@Builder(toBuilder = true)
public record UploadSettings(
        boolean uploadOnCapture,
        int concurrency,
        int maxAttempts,
        int retryBackoffSeconds,
        boolean waitOnQuit,
        boolean deleteLocalAfterUpload) {

    public static final int MAX_CONCURRENCY = 4;

    public static UploadSettings defaults() {
        return UploadSettings.builder()
                .uploadOnCapture(true)
                .concurrency(2)
                .maxAttempts(5)
                // Multiplied by 2^(attempt-1), so 5s grows to 80s by the fifth try.
                .retryBackoffSeconds(5)
                .waitOnQuit(true)
                .deleteLocalAfterUpload(false)
                .build();
    }

    UploadSettings normalized() {
        return toBuilder()
                .concurrency(Math.min(MAX_CONCURRENCY, Math.max(1, concurrency)))
                .maxAttempts(Math.min(20, Math.max(1, maxAttempts)))
                .retryBackoffSeconds(Math.min(300, Math.max(1, retryBackoffSeconds)))
                .build();
    }
}
