@prefix sb:    <https://byte.transaction.science/vocab/v1#> .
@prefix sh:    <http://www.w3.org/ns/shacl#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .

# Smart Byte v1 SHACL shapes — validates Byte / Envelope / AID /
# LockstepEvent against the v1 vocabulary before they enter
# replication. Catches malformed content hashes, wrong cargo-class
# tags, and broken lockstep chains.

sb:ByteShape a sh:NodeShape ;
    sh:targetClass sb:Byte ;
    sh:property [ sh:path sb:contentHash      ; sh:datatype xsd:string ; sh:minCount 1 ; sh:maxCount 1 ;
                  sh:pattern "^[a-f0-9]{64}$" ] ;
    sh:property [ sh:path sb:issuer           ; sh:nodeKind sh:IRI    ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path sb:cargo            ; sh:datatype xsd:string ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path sb:cargoClass       ; sh:nodeKind sh:IRI    ; sh:minCount 1 ; sh:maxCount 1 ;
                  sh:in ( sb:Value sb:Coding sb:Identity sb:Telemetry sb:Custom ) ] ;
    sh:property [ sh:path sb:joulesMicrojoules; sh:datatype xsd:nonNegativeInteger ; sh:maxCount 1 ] ;
    sh:property [ sh:path sb:energyProvenance ; sh:nodeKind sh:IRI    ; sh:maxCount 1 ;
                  sh:in ( sb:HwShunt sb:ModelBased sb:Estimator ) ] ;
    sh:property [ sh:path sb:issuedAt         ; sh:datatype xsd:dateTime ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path sb:sequence         ; sh:datatype xsd:nonNegativeInteger ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path sb:signature        ; sh:datatype xsd:string ; sh:minCount 1 ; sh:maxCount 1 ;
                  sh:pattern "^[a-f0-9]{128}$" ] .

sb:LockstepEventShape a sh:NodeShape ;
    sh:targetClass sb:LockstepEvent ;
    sh:property [ sh:path sb:previousHash   ; sh:datatype xsd:string             ; sh:minCount 1 ; sh:maxCount 1 ;
                  sh:pattern "^[a-f0-9]{64}$" ] ;
    sh:property [ sh:path sb:contentHash    ; sh:datatype xsd:string             ; sh:minCount 1 ; sh:maxCount 1 ;
                  sh:pattern "^[a-f0-9]{64}$" ] ;
    sh:property [ sh:path sb:lockstepHeight ; sh:datatype xsd:nonNegativeInteger ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path sb:signature      ; sh:datatype xsd:string             ; sh:minCount 1 ; sh:maxCount 1 ;
                  sh:pattern "^[a-f0-9]{128}$" ] .

sb:AIDShape a sh:NodeShape ;
    sh:targetClass sb:AID ;
    sh:property [ sh:path sb:aid       ; sh:datatype xsd:string   ; sh:minCount 1 ; sh:maxCount 1 ;
                  sh:pattern "^[A-Za-z0-9_-]+$" ] ;
    sh:property [ sh:path sb:rotatedAt ; sh:datatype xsd:dateTime ; sh:maxCount 1 ] .
