package dev.photosync.core.upload;

import dev.photosync.core.provider.UploadRequest;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.nio.file.Path;
import java.time.Instant;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * The description is captured once, at the moment the screenshot is taken, and
 * must survive the queue's persistence and retries unchanged -- it describes
 * the moment the shot was taken, not the moment it was sent.
 */
class UploadJobTest {

    private static final Instant TAKEN = Instant.parse("2026-08-08T12:00:00Z");

    @Test
    @DisplayName("the context captured at enqueue time travels with the upload")
    void descriptionSurvivesToRequest() {
        UploadJob job = UploadJob.builder()
                .id("job-1")
                .file("/tmp/shot.png")
                .fileName("shot.png")
                .sizeBytes(42)
                .capturedAt(TAKEN)
                .description("My Pack · play.example.com")
                .state(UploadState.PENDING)
                .attempts(0)
                .build();

        assertEquals("My Pack · play.example.com", job.toRequest().description());
    }

    @Test
    @DisplayName("a job restored from an old queue file has no description to send")
    void nullDescriptionBecomesEmpty() {
        UploadRequest request = new UploadRequest(
                Path.of("/tmp/shot.png"), "shot.png", TAKEN, TAKEN, null, null);

        assertEquals("", request.description());
    }
}
