@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix time: <http://www.w3.org/2006/time#> .
@prefix fsm: <https://secorolab.github.io/metamodels/behaviour/fsm#> .
@prefix el: <https://secorolab.github.io/metamodels/behaviour/event-loop#> .

fsm:FSMShape
  a sh:NodeShape ;
  sh:targetClass fsm:FiniteStateMachine ;

  sh:property [
    sh:path rdf:type ;
    sh:hasValue fsm:OrderedReactions ;
  ] ;

  sh:property [
    sh:path fsm:name ;
    sh:datatype xsd:string ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
  ] ;

  sh:property [
    sh:path fsm:description ;
    sh:datatype xsd:string ;
    sh:maxCount 1 ;
  ] ;

  sh:property [
    sh:path fsm:states ;
    sh:node fsm:StateShape ;
    sh:minCount 1 ;
  ] ;

  sh:property [
    sh:path fsm:start-state ;
    sh:class fsm:State ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
  ] ;

  sh:property [
    sh:path fsm:end-state ;
    sh:class fsm:State ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
  ] ;

  sh:property [
    sh:path fsm:current-state ;
    sh:class fsm:State ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
  ] ;

  sh:property [
    sh:path el:event-loop ;
    sh:class el:EventLoop ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
  ] ;

  sh:property [
    sh:path fsm:transitions ;
    sh:node fsm:TransitionShape ;
    sh:minCount 1 ;
  ] ;

  sh:property [
    sh:path fsm:reactions ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
  ] ;

  # An RDF list: the order of the reactions is their firing priority.
  sh:property [
    sh:path ( fsm:reactions [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ;
    sh:node fsm:ReactionShape ;
    sh:minCount 1 ;
  ] .

fsm:StateShape
  a sh:NodeShape ;
  sh:targetClass fsm:State .

fsm:TransitionShape
  a sh:NodeShape ;
  sh:targetClass fsm:Transition ;

  sh:property [
    sh:path fsm:transition-from ;
    sh:class fsm:State ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
  ] ;

  sh:property [
    sh:path fsm:transition-to ;
    sh:class fsm:State ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
  ] .

fsm:ReactionShape
  a sh:NodeShape ;
  sh:targetClass fsm:Reaction ;

  sh:property [
    sh:path rdf:type ;
    sh:hasValue el:EventReaction ;
  ] ;

  sh:property [
    sh:path fsm:do-transition ;
    sh:class fsm:Transition ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
  ] ;

  sh:property [
    sh:path fsm:fires-events ;
    sh:class time:Instant ;
  ] .
