package p.studio.workspaces.debug;

import org.junit.jupiter.api.Test;
import p.studio.execution.StudioExecutionLogEntry;
import p.studio.execution.StudioExecutionLogSeverity;
import p.studio.execution.StudioExecutionLogSource;
import p.studio.execution.StudioExecutionSnapshot;
import p.studio.execution.StudioExecutionState;

import java.time.Instant;
import java.util.List;

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

final class DebugWorkspaceProjectionTest {
    @Test
    void preservesSessionStateAndVisibleLogOrigins() {
        final StudioExecutionSnapshot snapshot = new StudioExecutionSnapshot(
                StudioExecutionState.PREPARING,
                List.of(
                        new StudioExecutionLogEntry(
                                1L,
                                Instant.parse("2026-04-06T10:00:00Z"),
                                StudioExecutionLogSource.BUILD,
                                StudioExecutionLogSeverity.INFO,
                                "Compiler started"),
                        new StudioExecutionLogEntry(
                                2L,
                                Instant.parse("2026-04-06T10:00:01Z"),
                                StudioExecutionLogSource.PACK,
                                StudioExecutionLogSeverity.ERROR,
                                "Pack failed")));

        final DebugWorkspaceProjection projection = DebugWorkspaceProjection.from(snapshot);

        assertEquals(StudioExecutionState.PREPARING, projection.state());
        assertEquals(2, projection.renderedLogs().size());
        assertTrue(projection.renderedLogs().getFirst().contains("[BUILD][INFO]"));
        assertTrue(projection.renderedLogs().getLast().contains("[PACK][ERROR]"));
    }
}
