package com.agent.management.rag.graph;

import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Map;

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

class GraphSchemaValidatorTest {
    private final GraphSchemaSnapshot schema = new GraphSchemaSnapshot(
            List.of(
                    new GraphSchemaSnapshot.NodeSchema("Mission", Map.of("name", List.of("STRING"))),
                    new GraphSchemaSnapshot.NodeSchema("Stage", Map.of("name", List.of("STRING"), "sequence", List.of("INTEGER"), "goal", List.of("STRING")))
            ),
            List.of(new GraphSchemaSnapshot.RelationshipSchema("HAS_STAGE", List.of("Mission"), List.of("Stage"), Map.of()))
    );
    private final GraphSchemaValidator validator = new GraphSchemaValidator();

    @Test
    void acceptsRealAuthorizedSchema() {
        validator.validate("MATCH (m:Mission)-[:HAS_STAGE]->(s:Stage) RETURN s.name, s.sequence, s.goal", schema, 3);
    }

    @Test
    void rejectsUnknownLabelRelationshipAndProperty() {
        assertThatThrownBy(() -> validator.validate("MATCH (n:Secret) RETURN n", schema, 3)).hasMessageContaining("label");
        assertThatThrownBy(() -> validator.validate("MATCH (:Mission)-[:UNKNOWN]->(:Stage) RETURN 1", schema, 3)).hasMessageContaining("relationship");
        assertThatThrownBy(() -> validator.validate("MATCH (s:Stage) RETURN s.secret", schema, 3)).hasMessageContaining("property");
    }

    @Test
    void rejectsUnboundedAndTooDeepPaths() {
        assertThatThrownBy(() -> validator.validate("MATCH (:Mission)-[:HAS_STAGE*]->(:Stage) RETURN 1", schema, 3)).hasMessageContaining("unbounded");
        assertThatThrownBy(() -> validator.validate("MATCH (:Mission)-[:HAS_STAGE*1..4]->(:Stage) RETURN 1", schema, 3)).hasMessageContaining("maxDepth");
    }
}
