@prefix ce: <https://ontology.inferal.com/profiles/ads-conversion-event-evidence/> .
@prefix ctx: <https://ontology.inferal.com/modules/commerce-transaction/> .
@prefix pc: <https://ontology.inferal.com/modules/commerce-purchase-classification/> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ce:ContextShape a sh:NodeShape ; sh:targetClass ce:EmissionContext ; sh:nodeKind sh:IRI ;
 sh:property [ sh:path ce:merchant ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path ce:receiver ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path ce:keyScope ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path ce:capturedAt ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:dateTimeStamp ] ;
 sh:property [ sh:path prov:wasDerivedFrom ; sh:minCount 1 ; sh:nodeKind sh:IRI ] .
ce:EventShape a sh:NodeShape ; sh:targetClass ce:EventRecord ; sh:nodeKind sh:IRI ;
 sh:property [ sh:path ce:context ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ; sh:class ce:EmissionContext ] ;
 sh:property [ sh:path ce:eventId ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:minLength 1 ] ;
 sh:property [ sh:path ce:eventName ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:minLength 1 ] ;
 sh:property [ sh:path ce:channel ; sh:minCount 1 ; sh:maxCount 1 ; sh:in (ce:Browser ce:Server) ] ;
 sh:property [ sh:path ce:occurredAt ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:dateTimeStamp ] ;
 sh:property [ sh:path prov:wasDerivedFrom ; sh:minCount 1 ; sh:nodeKind sh:IRI ] .
ce:ReceiverShape a sh:NodeShape ; sh:targetClass ce:ReceiverObservation ; sh:nodeKind sh:IRI ;
 sh:property [ sh:path ce:eventRecord ; sh:minCount 1 ; sh:maxCount 1 ; sh:class ce:EventRecord ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path ce:receiver ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path ce:reportedEffect ; sh:minCount 1 ; sh:maxCount 1 ; sh:in (ce:Accepted ce:Merged ce:Rejected) ] ;
 sh:property [ sh:path ce:policyReference ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path prov:wasDerivedFrom ; sh:minCount 1 ; sh:nodeKind sh:IRI ] ;
 sh:sparql [ sh:message "The receiver report must refer to the event context's receiver." ; sh:select """
 PREFIX ce: <https://ontology.inferal.com/profiles/ads-conversion-event-evidence/>
 SELECT $this WHERE { $this ce:receiver ?reported ; ce:eventRecord/ce:context/ce:receiver ?expected . FILTER (?reported != ?expected) }
 """ ] .
ce:PurchaseLinkShape a sh:NodeShape ; sh:targetClass ce:PurchaseLink ; sh:nodeKind sh:IRI ;
 sh:property [ sh:path ce:eventRecord ; sh:minCount 1 ; sh:maxCount 1 ; sh:class ce:EventRecord ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path ce:order ; sh:minCount 1 ; sh:maxCount 1 ; sh:class ctx:Order ; sh:nodeKind sh:IRI ;
   sh:node [ sh:property [ sh:path pc:merchant ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ] ] ] ;
 sh:property [ sh:path ce:merchant ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path prov:wasDerivedFrom ; sh:minCount 1 ; sh:nodeKind sh:IRI ] ;
 sh:sparql [ sh:message "Event, purchase and link must share the declared merchant scope." ; sh:select """
 PREFIX ce: <https://ontology.inferal.com/profiles/ads-conversion-event-evidence/>
 PREFIX pc: <https://ontology.inferal.com/modules/commerce-purchase-classification/>
 SELECT $this WHERE { $this ce:merchant ?merchant ; ce:order/pc:merchant ?orderMerchant ; ce:eventRecord/ce:context/ce:merchant ?eventMerchant .
 FILTER (?merchant != ?orderMerchant || ?merchant != ?eventMerchant) }
 """ ] .
ce:ChannelShape a sh:NodeShape ; sh:targetClass ce:Channel ; sh:in (ce:Browser ce:Server) .
ce:EffectShape a sh:NodeShape ; sh:targetClass ce:ReceiverEffect ; sh:in (ce:Accepted ce:Merged ce:Rejected) .
