@prefix co: <https://ontology.inferal.com/profiles/commerce-catalogue-observations/> .
@prefix schema: <https://schema.org/> .
@prefix aent: <https://ontology.inferal.com/modules/advertising-entity/> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

co:SnapshotShape a sh:NodeShape ; sh:targetClass co:CatalogueSnapshot ; sh:nodeKind sh:IRI ;
 sh:property [ sh:path co:merchantScope ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path co:catalogueScope ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path co:capturedAt ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:dateTimeStamp ] ;
 sh:property [ sh:path prov:wasDerivedFrom ; sh:minCount 1 ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path co:offerObservation ; sh:class co:OfferObservation ] .
co:OfferShape a sh:NodeShape ; sh:targetClass co:OfferObservation ; sh:nodeKind sh:IRI ;
 sh:property [ sh:path [ sh:inversePath co:offerObservation ] ; sh:minCount 1 ; sh:maxCount 1 ] ;
 sh:property [ sh:path co:recordedOffer ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ; sh:node co:RecordedOfferShape ] .
co:RecordedOfferShape a sh:NodeShape ; sh:class schema:Offer ;
 sh:property [ sh:path [ sh:inversePath co:recordedOffer ] ; sh:minCount 1 ; sh:maxCount 1 ] ;
 sh:property [ sh:path schema:itemOffered ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ; sh:class schema:Product ] ;
 sh:property [ sh:path schema:availability ; sh:maxCount 1 ; sh:nodeKind sh:IRI ;
   sh:in ( schema:InStock schema:OutOfStock schema:BackOrder schema:PreOrder schema:PreSale schema:SoldOut schema:Discontinued schema:LimitedAvailability schema:InStoreOnly schema:OnlineOnly ) ] .
co:ReferenceShape a sh:NodeShape ; sh:targetClass co:AdProductReference ; sh:nodeKind sh:IRI ;
 sh:property [ sh:path co:snapshot ; sh:minCount 1 ; sh:maxCount 1 ; sh:class co:CatalogueSnapshot ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path co:ad ; sh:minCount 1 ; sh:maxCount 1 ; sh:class aent:Ad ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path co:product ; sh:minCount 1 ; sh:maxCount 1 ; sh:class schema:Product ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path prov:wasDerivedFrom ; sh:minCount 1 ; sh:nodeKind sh:IRI ] ;
 sh:sparql [ sh:message "The referenced product must be explicitly observed in the selected snapshot." ; sh:select """
 PREFIX co: <https://ontology.inferal.com/profiles/commerce-catalogue-observations/>
 PREFIX schema: <https://schema.org/>
 SELECT $this WHERE { $this co:snapshot ?snapshot ; co:product ?product .
 FILTER NOT EXISTS { ?snapshot co:offerObservation/co:recordedOffer/schema:itemOffered ?product } }
 """ ] .
co:LinkStandingShape a sh:NodeShape ; sh:targetClass co:LinkStanding ; sh:in (co:DeclaredSameVariant co:PossibleMatch) .
co:IdentityShape a sh:NodeShape ; sh:targetClass co:IdentityAssertion ; sh:nodeKind sh:IRI ;
 sh:property [ sh:path co:leftProduct ; sh:minCount 1 ; sh:maxCount 1 ; sh:class schema:Product ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path co:rightProduct ; sh:minCount 1 ; sh:maxCount 1 ; sh:class schema:Product ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path co:leftSnapshot ; sh:minCount 1 ; sh:maxCount 1 ; sh:class co:CatalogueSnapshot ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path co:rightSnapshot ; sh:minCount 1 ; sh:maxCount 1 ; sh:class co:CatalogueSnapshot ; sh:nodeKind sh:IRI ] ;
 sh:property [ sh:path co:linkStanding ; sh:minCount 1 ; sh:maxCount 1 ; sh:in (co:DeclaredSameVariant co:PossibleMatch) ] ;
 sh:property [ sh:path prov:wasDerivedFrom ; sh:minCount 1 ; sh:nodeKind sh:IRI ] ;
 sh:sparql [ sh:message "Both identity endpoints need their explicitly selected captured product observations." ; sh:select """
 PREFIX co: <https://ontology.inferal.com/profiles/commerce-catalogue-observations/>
 PREFIX schema: <https://schema.org/>
 SELECT $this WHERE { $this co:leftProduct ?left ; co:rightProduct ?right ; co:leftSnapshot ?ls ; co:rightSnapshot ?rs .
 FILTER (NOT EXISTS { ?ls co:offerObservation/co:recordedOffer/schema:itemOffered ?left }
      || NOT EXISTS { ?rs co:offerObservation/co:recordedOffer/schema:itemOffered ?right }) }
 """ ] ;
 sh:sparql [ sh:message "A same-merchant-variant declaration cannot cross merchant scopes." ; sh:select """
 PREFIX co: <https://ontology.inferal.com/profiles/commerce-catalogue-observations/>
 SELECT $this WHERE { $this co:linkStanding co:DeclaredSameVariant ; co:leftSnapshot/co:merchantScope ?left ; co:rightSnapshot/co:merchantScope ?right . FILTER (?left != ?right) }
 """ ] .
