package click.kamil.springstatemachineexporter.service;

import click.kamil.springstatemachineexporter.exporter.StateMachineExporter;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

class ExportServiceEmptyStateTest {

    @TempDir
    Path tempDir;

    @Test
    void shouldSkipEmptyStateMachineConfigurations() throws Exception {
        // Arrange
        Path inputDir = tempDir.resolve("input");
        Files.createDirectories(inputDir);
        Path outputDir = tempDir.resolve("output");
        Files.createDirectories(outputDir);

        String code = """
                package com.example;
                import org.springframework.context.annotation.Configuration;
                import org.springframework.statemachine.config.EnableStateMachine;
                import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
                
                @Configuration
                @EnableStateMachine
                public class EmptyStateMachineConfig extends StateMachineConfigurerAdapter<String, String> {
                    // No configurers overridden, meaning 0 states and 0 transitions parsed
                }
                """;
        
        Files.writeString(inputDir.resolve("EmptyStateMachineConfig.java"), code);

        ExportService exportService = new ExportService(Collections.emptyList()); // No exporters needed, checking if it generates anything (it generates JSON natively)

        // Act
        exportService.runExporter(inputDir, outputDir, List.of("plantuml"), true);

        // Assert
        // The output directory should have no files created in it
        long fileCount = Files.walk(outputDir)
                .filter(Files::isRegularFile)
                .count();
        
        assertThat(fileCount).isZero();
    }
}
