@prefix sh:   <http://www.w3.org/ns/shacl#> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
@prefix pdep: <https://aips.kivanura.org/spec/aips/pdep/0.1/> .
@prefix aips: <https://aips.kivanura.org/spec/aips/0.1/> .

pdep:PDEPLifecycleRecordShape a sh:NodeShape ;
  sh:targetClass pdep:PDEPLifecycleRecord ;
  sh:property [ sh:path pdep:productIdentity ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ] ;
  sh:property [ sh:path pdep:candidateProductVersion ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ] ;
  sh:property [ sh:path pdep:currentStage ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 0 ; sh:maxInclusive 11 ] ;
  sh:property [ sh:path pdep:gateDecision ; sh:minCount 1 ] .

pdep:StageSevenCompilationShape a sh:NodeShape ;
  sh:targetClass pdep:PDEPLifecycleRecord ;
  sh:sparql [
    a sh:SPARQLConstraint ;
    sh:message "At Stage 7 or later, definitive AI qualification and Governance Obligation Profile references are required." ;
    sh:select """
      SELECT $this WHERE {
        {
          $this pdep:currentStage ?stage .
          FILTER (?stage >= 7)
          FILTER NOT EXISTS { $this pdep:definitiveQualification ?q . }
        }
        UNION
        {
          $this pdep:currentStage ?stage2 .
          FILTER (?stage2 >= 7)
          FILTER NOT EXISTS { $this pdep:governanceProfileRef ?g . }
        }
      }
    """
  ] .

pdep:PromotionCurrentnessShape a sh:NodeShape ;
  sh:targetClass pdep:PDEPLifecycleRecord ;
  sh:sparql [
    a sh:SPARQLConstraint ;
    sh:message "Stage 10 promotion requires CURRENT qualification, dependency, governance and assurance currentness." ;
    sh:select """
      SELECT $this WHERE {
        $this pdep:currentStage 10 ; pdep:trustCurrentness ?t .
        {
          FILTER NOT EXISTS { ?t pdep:qualificationCurrentness aips:CURRENT . }
        } UNION {
          FILTER NOT EXISTS { ?t pdep:dependencyCurrentness aips:CURRENT . }
        } UNION {
          FILTER NOT EXISTS { ?t pdep:governanceCurrentness aips:CURRENT . }
        } UNION {
          FILTER NOT EXISTS { ?t pdep:assuranceCurrentness aips:CURRENT . }
        }
      }
    """
  ] .
