@prefix sh:     <http://www.w3.org/ns/shacl#> .
@prefix rs:     <https://robosystems.ai/vocab/> .
@prefix xbrli:  <http://www.xbrl.org/2003/instance#> .
@prefix xlink:  <http://www.w3.org/1999/xlink#> .
@prefix link:   <http://www.xbrl.org/2003/linkbase#> .
@prefix xsd:    <http://www.w3.org/2001/XMLSchema#> .

#################################################################
# SHACL shapes for the rs: vocabulary outside a holon: a framework
# package (frameworks/**/taxonomy.jsonld) and the JSON-LD xbrlkit's
# serializer writes. Terms are declared in ontology.ttl.
#
# Positive shapes say what a fact, a dimension and an arc carry. One
# negative shape rejects XBRL context syntax: a fact carries its
# period, entity and unit directly. A retired rs: term needs no shape:
# the ontology no longer declares it, and robosystems' vocabulary
# test fails any package, context or shape that uses an undeclared
# term.
#
# One file, two homes: robosystems frameworks/ontology/v1/shapes.ttl
# is the source; xbrlkit _vendor/ontology/v1/shapes.ttl is a verbatim
# copy. Edit the source and copy it across. A holon has its own,
# fuller shapes, one file per named graph, in xbrlkit/holon/shapes/.
#################################################################

# -- Positive: a Fact references its aspects directly (no context) --
# A numeric fact carries rs:unit + rs:numericValue; a non-numeric (text /
# textBlock) fact carries rs:stringValue and no unit. Both are Facts; the
# value predicate distinguishes them (rs:factType records which). No package
# carries facts today; the holon's rs:Fact shape is in xbrlkit.
rs:FactShape a sh:NodeShape ;
  sh:targetClass rs:Fact ;
  sh:property [
    sh:path rs:element ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ;
    sh:message "rs:Fact must reference exactly one rs:element (IRI)." ] ;
  sh:property [
    sh:path rs:period ; sh:minCount 1 ; sh:maxCount 1 ;
    sh:message "rs:Fact must reference exactly one rs:period." ] ;
  sh:property [
    sh:path rs:unit ; sh:maxCount 1 ;
    sh:message "rs:Fact may reference at most one rs:unit." ] ;
  sh:property [
    sh:path rs:numericValue ; sh:datatype xsd:decimal ; sh:maxCount 1 ] ;
  sh:property [
    sh:path rs:stringValue ; sh:maxCount 1 ;
    sh:message "rs:Fact may carry at most one rs:stringValue (non-numeric value)." ] ;
  sh:property [
    sh:path rs:factType ; sh:maxCount 1 ] .

# -- Positive: a Dimension carries its axis (+ explicit member or typed value) --
rs:DimensionShape a sh:NodeShape ;
  sh:targetClass rs:Dimension ;
  sh:property [
    sh:path rs:axis ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ;
    sh:message "rs:Dimension must reference exactly one rs:axis (the axis Element IRI)." ] ;
  sh:property [
    sh:path rs:member ; sh:maxCount 1 ; sh:nodeKind sh:IRI ;
    sh:message "rs:Dimension references at most one explicit rs:member (Element IRI); typed dimensions use rs:typedValue instead." ] ;
  sh:property [
    sh:path rs:typedValue ; sh:maxCount 1 ] ;
  sh:property [
    sh:path rs:isExplicit ; sh:maxCount 1 ] ;
  sh:property [
    sh:path rs:isTyped ; sh:maxCount 1 ] .

# ── Positive: a reified Association carries XBRL arc vocabulary ──
rs:AssociationShape a sh:NodeShape ;
  sh:targetClass rs:Association ;
  sh:property [
    sh:path xlink:from ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ;
    sh:message "rs:Association must have exactly one xlink:from (IRI)." ] ;
  sh:property [
    sh:path xlink:to ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ;
    sh:message "rs:Association must have exactly one xlink:to (IRI)." ] ;
  sh:property [
    sh:path rs:associationType ; sh:minCount 1 ; sh:maxCount 1 ;
    sh:message "rs:Association must declare exactly one rs:associationType." ] ;
  sh:property [
    sh:path xlink:arcrole ; sh:maxCount 1 ;
    sh:message "rs:Association may carry at most one xlink:arcrole (rs-native types like 'derivation' have none)." ] ;
  # weight/order are numeric, at most one each. The XSD subtype is left
  # unpinned: JSON-LD coerces JSON floats to ill-typed xsd:decimal literals
  # (float value + decimal datatype), which a strict sh:datatype would reject
  # — the producer guarantees they're numbers; the loader reads float().
  sh:property [
    sh:path link:weight ; sh:maxCount 1 ] ;
  sh:property [
    sh:path link:order ; sh:maxCount 1 ] .

# ── Negative: ban XBRL context syntax (the collapse is enforced) ──
rs:NoXbrlContextShape a sh:NodeShape ;
  sh:targetSubjectsOf xbrli:contextRef ;
  sh:property [
    sh:path xbrli:contextRef ; sh:maxCount 0 ;
    sh:message "xbrli:contextRef is XBRL syntax — facts carry rs:period/entity/unit directly. Derive contexts in the XBRL encoder only." ] .
