# AssessorAccreditedForScope — DCC issuer DIA covers this scheme or profile.

@prefix sh:     <http://www.w3.org/ns/shacl#> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:    <http://www.w3.org/2002/07/owl#> .
@prefix xsd:    <http://www.w3.org/2001/XMLSchema#> .
@prefix cred:   <https://www.w3.org/2018/credentials#> .
@prefix unece:  <https://test.uncefact.org/vocabulary/> .
@prefix gv:     <https://vocabulary.uncefact.org/untp/shapes/> .

gv:AssessorAccreditedForScope
    a owl:Ontology, sh:NodeShape ;
    owl:versionInfo "0.8.0" ;
    rdfs:label "Assessor accredited for scope"@en ;
    rdfs:comment "The issuer of a conformity credential must have a Digital Identity Anchor whose recognitionScope covers the scheme or profile of the attestation. Accreditation for one scheme does not authorise assessments under another."@en ;
    rdfs:seeAlso <https://untp.unece.org/docs/specification/ConformityCredential> ,
                 <https://untp.unece.org/docs/specification/DigitalIdentityAnchor> ;
    sh:declare
        [ sh:prefix "cred" ; sh:namespace "https://www.w3.org/2018/credentials#"^^xsd:anyURI ] ,
        [ sh:prefix "unece" ; sh:namespace "https://test.uncefact.org/vocabulary/"^^xsd:anyURI ] ;
    sh:targetClass unece:ConformityAttestation ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "The issuer of this conformity attestation has no Digital Identity Anchor whose recognitionScope covers the referenced scheme or profile."@en ;
        sh:prefixes gv:AssessorAccreditedForScope ;
        sh:select """
            PREFIX cred:  <https://www.w3.org/2018/credentials#>
            PREFIX unece: <https://test.uncefact.org/vocabulary/>
            SELECT $this ?issuer ?scopeRef
            WHERE {
              ?cred cred:credentialSubject $this ;
                    cred:issuer ?issuer .
              { $this unece:referenceScheme ?scopeRef }
              UNION
              { $this unece:referenceProfile ?scopeRef }
              FILTER NOT EXISTS {
                ?issuer a unece:RegisteredIdentity ;
                        unece:recognitionScope ?scopeRef .
              }
            }
        """ ;
    ] .
