package com.ai.trackwalker.model;

import org.junit.jupiter.api.Test;
import org.springframework.web.server.ResponseStatusException;

import java.util.List;

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

class ModelArtifactLifecycleServiceTest {
    @Test
    void exposesRequiredPackageComponentsByModelGroup() {
        assertEquals(List.of("primary", "labels"),
                ModelArtifactLifecycleService.requiredComponents("vision-detector"));
        assertEquals(List.of("primary", "secondary", "labels"),
                ModelArtifactLifecycleService.requiredComponents("thermal-analyzer"));
        assertEquals(List.of(),
                ModelArtifactLifecycleService.requiredComponents("pointcloud-analyzer"));
    }

    @Test
    void normalizesUploadedFileNameWithoutAllowingTraversal() {
        assertEquals("model.onnx", ModelArtifactLifecycleService.safeFileName("../model.onnx", "model.onnx"));
        assertEquals("rail_model.onnx", ModelArtifactLifecycleService.safeFileName("rail model.onnx", "model.onnx"));
        assertThrows(ResponseStatusException.class,
                () -> ModelArtifactLifecycleService.safeFileName("..", "model.onnx"));
    }
}
