# baseURI: https://ekgf.org/dprod/spec/develop/contracts/shapes/
# imports: https://ekgf.org/dprod/spec/develop/contracts/
# imports: http://www.w3.org/ns/shacl#
# prefix: dprod-contracts-shapes

@base <https://ekgf.org/dprod/spec/develop/contracts/shapes/> .
@prefix dprod-contracts-shapes: <https://ekgf.org/dprod/spec/develop/contracts/shapes/> .
@prefix dprod: <https://ekgf.org/dprod/spec/develop/> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix odrl: <http://www.w3.org/ns/odrl/2/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

dprod-contracts-shapes:
  a owl:Ontology ;
  dct:title "Shapes for DPROD Data Contracts"@en ;
  rdfs:label "DPROD contracts shapes"@en ;
  dct:description "SHACL validation shapes for DPROD data contract policies."@en ;
  rdfs:comment
    "This is intended to be used with SHACL, not as an ontology: the ontology element is to provide the metadata for the set of shapes."@en ;
  dct:license <https://creativecommons.org/licenses/by/4.0/> ;
  dct:modified "2026-10-13"^^xsd:date ;
  owl:imports <https://ekgf.org/dprod/spec/develop/contracts/> ;
  owl:imports sh: ;
  owl:versionInfo "0.7" ;
  sh:declare [
    sh:prefix "dprod" ;
    sh:namespace "https://ekgf.org/dprod/spec/develop/" ;
  ] ;
  sh:declare [
    sh:prefix "dprod-contracts-shapes" ;
    sh:namespace "https://ekgf.org/dprod/spec/develop/contracts/shapes/" ;
  ] ;
  sh:declare [
    sh:prefix "odrl" ;
    sh:namespace "http://www.w3.org/ns/odrl/2/" ;
  ] ;
.


############################# Reusable Property Groups #########################


dprod-contracts-shapes:OfferLifecycleStatusPropertyGroup
  a sh:PropertyShape ;
  sh:name "offer lifecycle status" ;
  sh:description "Optional authored lifecycle status for a DataOffer. The value must be a skos:Concept; DPROD's scheme is optional and profiles may use an enterprise taxonomy."@en ;
  sh:path dprod:offerLifecycleStatus ;
  sh:maxCount 1 ;
  sh:nodeKind sh:IRI ;
  sh:class skos:Concept ;
  sh:message "offerLifecycleStatus, if present, must be a single skos:Concept value." ;
.

dprod-contracts-shapes:ContractLifecycleStatusPropertyGroup
  a sh:PropertyShape ;
  sh:name "contract lifecycle status" ;
  sh:description "Optional authored lifecycle status for a DataContract. The value must be a skos:Concept; DPROD's scheme is optional and profiles may use an enterprise taxonomy."@en ;
  sh:path dprod:contractLifecycleStatus ;
  sh:maxCount 1 ;
  sh:nodeKind sh:IRI ;
  sh:class skos:Concept ;
  sh:message "contractLifecycleStatus, if present, must be a single skos:Concept value." ;
.

dprod-contracts-shapes:DutyStatePropertyGroup
  a sh:PropertyShape ;
  sh:name "duty state" ;
  sh:description "Optional evaluated state for a Duty. Value must be a skos:Concept; the four DPROD-defined concepts (Pending, Active, Fulfilled, Violated) are the canonical vocabulary that the standard evaluation algorithm transitions between."@en ;
  sh:path dprod:dutyState ;
  sh:maxCount 1 ;
  sh:nodeKind sh:IRI ;
  sh:class skos:Concept ;
  sh:message "dutyState, if present, must be a single skos:Concept value." ;
.

dprod-contracts-shapes:ProfilePropertyGroup
  a sh:PropertyShape ;
  sh:name "profile" ;
  sh:description "The ODRL profile IRI a policy must declare to be recognised as DPROD. Reused by Set, Offer, Agreement, DataOffer, and DataContract shapes."@en ;
  sh:path odrl:profile ;
  sh:minCount 1 ;
  sh:hasValue <https://ekgf.org/dprod/spec/develop/contracts/profile/> ;
  sh:message "DPROD policies must declare odrl:profile <https://ekgf.org/dprod/spec/develop/contracts/profile/>." ;
.

dprod-contracts-shapes:NonEmptyClausesConstraint
  a sh:NodeShape ;
  rdfs:label "non-empty clauses constraint" ;
  dct:description "Reusable node constraint requiring a DPROD policy to carry at least one rule: an odrl:permission, odrl:prohibition or odrl:obligation. Set, Offer, Agreement, DataOffer and DataContract shapes apply it through sh:node."@en ;
  sh:or (
    [ sh:property [ sh:path odrl:permission ; sh:minCount 1 ] ]
    [ sh:property [ sh:path odrl:prohibition ; sh:minCount 1 ] ]
    [ sh:property [ sh:path odrl:obligation ; sh:minCount 1 ] ]
  ) ;
  sh:message "Policy must have at least one permission, prohibition, or obligation." ;
.


############################# Policy Shapes #########################


dprod-contracts-shapes:PolicyShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "policy shape" ;
  dct:description "Validates every odrl:Policy, whatever its subclass, by requiring it to declare odrl:profile with the DPROD contracts profile IRI, so that only policies that opt into DPROD semantics are evaluated by DPROD."@en ;
  sh:targetClass odrl:Policy ;
  sh:name "Policy Shape" ;
  sh:property [
    sh:path odrl:profile ;
    sh:minCount 1 ;
    sh:hasValue <https://ekgf.org/dprod/spec/develop/contracts/profile/> ;
    sh:message "DPROD policies must declare odrl:profile <https://ekgf.org/dprod/spec/develop/contracts/profile/>."
  ] ;
.

dprod-contracts-shapes:SetShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "set shape" ;
  dct:description "Validates an odrl:Set policy as a DPROD policy: it must declare the DPROD contracts profile and contain at least one permission, prohibition or obligation. A policy-level odrl:target is allowed and is inherited by the policy's rules."@en ;
  sh:targetClass odrl:Set ;
  sh:name "Set Shape" ;
  sh:property dprod-contracts-shapes:ProfilePropertyGroup ;
  sh:node dprod-contracts-shapes:NonEmptyClausesConstraint ;
  sh:property [
    sh:path odrl:target ;
    sh:message "Set policy may declare a policy-level target (inherited by rules)."
  ] ;
.

dprod-contracts-shapes:OfferShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "offer shape" ;
  dct:description "Validates an odrl:Offer policy as a DPROD policy: it must declare the DPROD contracts profile, contain at least one permission, prohibition or obligation, and name exactly one odrl:assigner, the party making the offer."@en ;
  sh:targetClass odrl:Offer ;
  sh:name "Offer Shape" ;
  sh:property dprod-contracts-shapes:ProfilePropertyGroup ;
  sh:node dprod-contracts-shapes:NonEmptyClausesConstraint ;
  sh:property [
    sh:path odrl:assigner ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:message "Offer must have exactly one assigner."
  ] ;
.

dprod-contracts-shapes:AgreementShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "agreement shape" ;
  dct:description "Validates an odrl:Agreement policy as a DPROD policy: it must declare the DPROD contracts profile, contain at least one permission, prohibition or obligation, and name exactly one odrl:assigner and exactly one odrl:assignee."@en ;
  sh:targetClass odrl:Agreement ;
  sh:name "Agreement Shape" ;
  sh:property dprod-contracts-shapes:ProfilePropertyGroup ;
  sh:node dprod-contracts-shapes:NonEmptyClausesConstraint ;
  sh:property [
    sh:path odrl:assigner ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:message "Agreement must have exactly one assigner."
  ] ;
  sh:property [
    sh:path odrl:assignee ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:message "Agreement must have exactly one assignee."
  ] ;
.


############################# Rule Shapes #########################


dprod-contracts-shapes:PermissionShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "permission shape" ;
  dct:description "Validates an odrl:Permission rule: it must have exactly one odrl:action and at most one odrl:target. When the target is absent, the permission inherits the policy-level target."@en ;
  sh:targetClass odrl:Permission ;
  sh:name "Permission Shape" ;
  sh:property [
    sh:path odrl:action ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:message "Permission must have exactly one action."
  ] ;
  sh:property [
    sh:path odrl:target ;
    sh:maxCount 1 ;
    sh:message "Permission may have at most one target (inherits from policy if absent)."
  ] ;
.

dprod-contracts-shapes:ProhibitionShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "prohibition shape" ;
  dct:description "Validates an odrl:Prohibition rule: it must have exactly one odrl:action and at most one odrl:target. When the target is absent, the prohibition inherits the policy-level target."@en ;
  sh:targetClass odrl:Prohibition ;
  sh:name "Prohibition Shape" ;
  sh:property [
    sh:path odrl:action ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:message "Prohibition must have exactly one action."
  ] ;
  sh:property [
    sh:path odrl:target ;
    sh:maxCount 1 ;
    sh:message "Prohibition may have at most one target (inherits from policy if absent)."
  ] ;
.

dprod-contracts-shapes:DutyShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "duty shape" ;
  dct:description "Validates an odrl:Duty: it must have exactly one odrl:action and may carry at most one each of dprod:deadline (an xsd:dateTime or xsd:duration), dprod:schedule (an identified dprod:Schedule), dprod:subjectOfDuty and dprod:objectOfDuty (each an odrl:Party), and dprod:dutyState (a skos:Concept)."@en ;
  sh:targetClass odrl:Duty ;
  sh:name "Duty Shape" ;
  sh:property [
    sh:path odrl:action ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:message "Duty must have exactly one action."
  ] ;
  sh:property [
    sh:path dprod:deadline ;
    sh:maxCount 1 ;
    sh:or (
      [ sh:datatype xsd:dateTime ]
      [ sh:datatype xsd:duration ]
    ) ;
    sh:message "Deadline must be xsd:dateTime or xsd:duration."
  ] ;
  sh:property [
    sh:path dprod:schedule ;
    sh:maxCount 1 ;
    sh:nodeKind sh:IRI ;
    sh:class dprod:Schedule ;
    sh:message "Duty schedule must be a single IRI identifying a dprod:Schedule."
  ] ;
  sh:property [
    sh:path dprod:subjectOfDuty ;
    sh:maxCount 1 ;
    sh:class odrl:Party ;
    sh:message "Duty subject must be a single odrl:Party."
  ] ;
  sh:property [
    sh:path dprod:objectOfDuty ;
    sh:maxCount 1 ;
    sh:class odrl:Party ;
    sh:message "Duty object must be a single odrl:Party."
  ] ;
  sh:property dprod-contracts-shapes:DutyStatePropertyGroup ;
.

# Duty-only properties (#239). Their OWL domains infer odrl:Duty rather than
# validate it, so a Permission or Prohibition carrying one would silently gain
# a second, ODRL-disjoint rule type. Reject that explicitly: the subject must be
# a Duty and must not be a Permission or Prohibition, whatever inference says.
# dprod:schedule is not duty-only (it has no domain), and the obsolete
# dprod:recurrence is rejected on every subject by RejectObsoleteRecurrenceShape.
dprod-contracts-shapes:DutyOnlyPropertiesShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "duty-only properties shape" ;
  dct:description "Ensures that dprod:deadline, dprod:subjectOfDuty and dprod:objectOfDuty are used only on duties. Their subject must be an odrl:Duty and must not also be an odrl:Permission or odrl:Prohibition, so OWL domain inference cannot silently give a rule a second, ODRL-disjoint rule type."@en ;
  sh:name "Duty-Only Properties Shape" ;
  sh:targetSubjectsOf dprod:deadline, dprod:subjectOfDuty, dprod:objectOfDuty ;
  sh:class odrl:Duty ;
  sh:not [ sh:class odrl:Permission ] ;
  sh:not [ sh:class odrl:Prohibition ] ;
  sh:message "dprod:deadline, dprod:subjectOfDuty and dprod:objectOfDuty are duty-only: the subject must be an odrl:Duty and not an odrl:Permission or odrl:Prohibition." ;
.


############################# Schedule Shapes #########################


dprod-contracts-shapes:ScheduleReferenceShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "schedule reference shape" ;
  dct:description "Validates every use of dprod:schedule: each value must be an IRI that identifies a dprod:Schedule, never a blank node or literal."@en ;
  sh:targetSubjectsOf dprod:schedule ;
  sh:property [
    sh:path dprod:schedule ;
    sh:nodeKind sh:IRI ;
    sh:class dprod:Schedule ;
    sh:message "Schedule references must be IRIs identifying dprod:Schedule resources."
  ] ;
.

# The IRI-identifier requirement lives in its own shape so its message is
# attached only to nodeKind violations, not to every ScheduleShape result.
# It is named Reject* so the spec generator does not render it as a second
# Schedule class.
dprod-contracts-shapes:RejectAnonymousScheduleShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "reject anonymous schedule" ;
  dct:description "Requires every dprod:Schedule to be identified by an IRI, so a schedule can be referenced, shared and audited. Kept separate from the schedule shape so its message applies only to blank-node schedules."@en ;
  sh:targetClass dprod:Schedule ;
  sh:nodeKind sh:IRI ;
  sh:message "A Schedule must have an IRI identifier." ;
.

# Every ScheduleFormat, including third-party extensions, must state whether
# its expressions embed a timezone; the ScheduleShape timezone rule keys on it.
dprod-contracts-shapes:ScheduleFormatShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "schedule format shape" ;
  dct:description "Validates a dprod:ScheduleFormat, including third-party formats: it must state exactly once, as an xsd:boolean dprod:carriesTimeZone, whether its expressions embed a timezone. The schedule shape relies on this to enforce timezone completeness."@en ;
  sh:targetClass dprod:ScheduleFormat ;
  sh:property [
    sh:path dprod:carriesTimeZone ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:datatype xsd:boolean ;
    sh:message "A ScheduleFormat must declare dprod:carriesTimeZone so validators can enforce timezone completeness."
  ] ;
.

dprod-contracts-shapes:ScheduleShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "schedule shape" ;
  dct:description "Validates a dprod:Schedule: it must conform to exactly one identified dprod:ScheduleFormat through dct:conformsTo and carry exactly one dprod:scheduleExpression string, with an optional IANA dprod:scheduleTimeZone. RFC 5545 expressions must contain DTSTART with a TZID and an RRULE, and a declared timezone must match that TZID. POSIX crontab expressions must have exactly five fields. A schedule whose format carries no timezone must declare one."@en ;
  sh:targetClass dprod:Schedule ;
  sh:property [
    sh:path dct:conformsTo ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:nodeKind sh:IRI ;
    sh:or (
      [ sh:in (dprod:Rfc5545ScheduleFormat dprod:PosixCrontabScheduleFormat) ]
      [ sh:class dprod:ScheduleFormat ]
    ) ;
    sh:message "Schedule format must be an identified dprod:ScheduleFormat."
  ] ;
  sh:property [
    sh:path dprod:scheduleExpression ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:datatype xsd:string ;
    sh:message "Schedule must have exactly one authoritative expression as an xsd:string."
  ] ;
  sh:property [
    sh:path dprod:scheduleTimeZone ;
    sh:maxCount 1 ;
    sh:datatype xsd:string ;
    sh:pattern "^[A-Za-z0-9._+-]+(/[A-Za-z0-9._+-]+)*$" ;
    sh:message "scheduleTimeZone must be one IANA timezone name."
  ] ;
  sh:sparql [
    sh:message "RFC 5545 schedules must include DTSTART with TZID and RRULE (optionally EXDATE/RDATE lines); RRULE parts must be standard and must not repeat FREQ." ;
    sh:select """
      PREFIX dct: <http://purl.org/dc/terms/>
      PREFIX dprod: <https://ekgf.org/dprod/spec/develop/>
      SELECT $this
      WHERE {
        $this dct:conformsTo dprod:Rfc5545ScheduleFormat ;
              dprod:scheduleExpression ?expression .
        FILTER (!REGEX(
          STR(?expression),
          "^DTSTART;TZID=[A-Za-z0-9._+-]+(/[A-Za-z0-9._+-]+)*:[0-9]{8}T[0-9]{6}(\\r?\\n(EXDATE|RDATE)(;[A-Za-z0-9-]+=[^:;\\r\\n]+)*:[^\\r\\n]+)*\\r?\\nRRULE:FREQ=(SECONDLY|MINUTELY|HOURLY|DAILY|WEEKLY|MONTHLY|YEARLY)(;(UNTIL|COUNT|INTERVAL|BYSECOND|BYMINUTE|BYHOUR|BYDAY|BYMONTHDAY|BYYEARDAY|BYWEEKNO|BYMONTH|BYSETPOS|WKST)=[^;\\r\\n]+)*(\\r?\\n(EXDATE|RDATE)(;[A-Za-z0-9-]+=[^:;\\r\\n]+)*:[^\\r\\n]+)*$"
        ))
      }
    """ ;
  ] ;
  sh:sparql [
    sh:message "scheduleTimeZone must match the TZID embedded in the RFC 5545 expression." ;
    sh:select """
      PREFIX dct: <http://purl.org/dc/terms/>
      PREFIX dprod: <https://ekgf.org/dprod/spec/develop/>
      SELECT $this
      WHERE {
        $this dct:conformsTo dprod:Rfc5545ScheduleFormat ;
              dprod:scheduleExpression ?expression ;
              dprod:scheduleTimeZone ?timeZone .
        BIND (REPLACE(STR(?expression), "^DTSTART;TZID=([^:]+):(.|\\n|\\r)*$", "$1") AS ?embedded)
        FILTER (STR(?timeZone) != ?embedded)
      }
    """ ;
  ] ;
  sh:sparql [
    sh:message "POSIX crontab schedules must contain exactly five time fields." ;
    sh:select """
      PREFIX dct: <http://purl.org/dc/terms/>
      PREFIX dprod: <https://ekgf.org/dprod/spec/develop/>
      SELECT $this
      WHERE {
        $this dct:conformsTo dprod:PosixCrontabScheduleFormat ;
              dprod:scheduleExpression ?expression .
        FILTER (
          !REGEX(STR(?expression), "^([^ \\t\\r\\n]+[ \\t]+){4}[^ \\t\\r\\n]+$") ||
          CONTAINS(STR(?expression), "\\n") ||
          CONTAINS(STR(?expression), "\\r")
        )
      }
    """ ;
  ] ;
  sh:sparql [
    sh:message "Schedules whose format carries no timezone must declare one IANA timezone." ;
    sh:select """
      PREFIX dct: <http://purl.org/dc/terms/>
      PREFIX dprod: <https://ekgf.org/dprod/spec/develop/>
      SELECT $this
      WHERE {
        $this dct:conformsTo ?format .
        FILTER (?format = dprod:PosixCrontabScheduleFormat ||
                EXISTS { ?format dprod:carriesTimeZone false })
        FILTER NOT EXISTS { $this dprod:scheduleTimeZone ?timeZone }
      }
    """ ;
  ] ;
.

dprod-contracts-shapes:RejectObsoleteRecurrenceShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "reject obsolete recurrence property" ;
  dct:description "Rejects the obsolete dprod:recurrence property on any subject. Recurring obligations are expressed with dprod:schedule referencing an identified dprod:Schedule."@en ;
  sh:targetSubjectsOf dprod:recurrence ;
  sh:property [
    sh:path dprod:recurrence ;
    sh:maxCount 0 ;
    sh:severity sh:Violation ;
    sh:message
      "dprod:recurrence is obsolete; use dprod:schedule with an identified dprod:Schedule."
  ] ;
.


############################# Constraint Shapes #########################


dprod-contracts-shapes:ConstraintShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "constraint shape" ;
  dct:description "Validates an odrl:Constraint: it must have exactly one odrl:leftOperand, exactly one odrl:operator and at least one odrl:rightOperand."@en ;
  sh:targetClass odrl:Constraint ;
  sh:name "Constraint Shape" ;
  sh:property [
    sh:path odrl:leftOperand ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:message "Constraint must have exactly one leftOperand."
  ] ;
  sh:property [
    sh:path odrl:operator ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:message "Constraint must have exactly one operator."
  ] ;
  sh:property [
    sh:path odrl:rightOperand ;
    sh:minCount 1 ;
    sh:message "Constraint must have a rightOperand."
  ] ;
.

dprod-contracts-shapes:LogicalConstraintShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "logical constraint shape" ;
  dct:description "Validates an odrl:LogicalConstraint: it must use exactly one of the logical operators odrl:and, odrl:or or dprod:not, each with a single operand list."@en ;
  sh:targetClass odrl:LogicalConstraint ;
  sh:name "Logical Constraint Shape" ;
  sh:xone (
    [ sh:property [ sh:path odrl:and ; sh:minCount 1 ; sh:maxCount 1 ] ]
    [ sh:property [ sh:path odrl:or ; sh:minCount 1 ; sh:maxCount 1 ] ]
    [ sh:property [ sh:path dprod:not ; sh:minCount 1 ; sh:maxCount 1 ] ]
  ) ;
  sh:message "LogicalConstraint must have exactly one of: odrl:and, odrl:or, or dprod:not." ;
.


############################# Contract Shapes #########################


dprod-contracts-shapes:DataOfferShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "data offer shape" ;
  dct:description "Validates a dprod:DataOffer: it must declare the DPROD contracts profile, contain at least one permission, prohibition or obligation, and name exactly one odrl:assigner, the data provider. It may carry one dprod:offerLifecycleStatus and single xsd:dateTime values for dprod:effectiveDate and dprod:expirationDate."@en ;
  sh:targetClass dprod:DataOffer ;
  sh:name "Data Offer Shape" ;
  sh:property dprod-contracts-shapes:ProfilePropertyGroup ;
  sh:node dprod-contracts-shapes:NonEmptyClausesConstraint ;
  sh:property [
    sh:path odrl:assigner ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:message "DataOffer must have exactly one assigner."
  ] ;
  sh:property dprod-contracts-shapes:OfferLifecycleStatusPropertyGroup ;
  sh:property [
    sh:path dprod:effectiveDate ;
    sh:maxCount 1 ;
    sh:datatype xsd:dateTime ;
    sh:message "effectiveDate, if present, must be a single xsd:dateTime value."
  ] ;
  sh:property [
    sh:path dprod:expirationDate ;
    sh:maxCount 1 ;
    sh:datatype xsd:dateTime ;
    sh:message "expirationDate, if present, must be a single xsd:dateTime value."
  ] ;
.

dprod-contracts-shapes:DataContractShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "data contract shape" ;
  dct:description "Validates a dprod:DataContract: it must declare the DPROD contracts profile, contain at least one permission, prohibition or obligation, name exactly one odrl:assigner (the data provider) and one odrl:assignee (the data consumer), and accept exactly one dprod:DataOffer through dprod:acceptsOffer. It may carry one dprod:contractLifecycleStatus and single xsd:dateTime values for dprod:effectiveDate and dprod:expirationDate."@en ;
  sh:targetClass dprod:DataContract ;
  sh:name "Data Contract Shape" ;
  sh:property dprod-contracts-shapes:ProfilePropertyGroup ;
  sh:node dprod-contracts-shapes:NonEmptyClausesConstraint ;
  sh:property [
    sh:path odrl:assigner ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:message "DataContract must have exactly one assigner (data provider)."
  ] ;
  sh:property [
    sh:path odrl:assignee ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:message "DataContract must have exactly one assignee (data consumer)."
  ] ;
  sh:property [
    sh:path dprod:acceptsOffer ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:class dprod:DataOffer ;
    sh:message "DataContract must reference exactly one DataOffer."
  ] ;
  sh:property dprod-contracts-shapes:ContractLifecycleStatusPropertyGroup ;
  sh:property [
    sh:path dprod:effectiveDate ;
    sh:maxCount 1 ;
    sh:datatype xsd:dateTime ;
    sh:message "effectiveDate, if present, must be a single xsd:dateTime value."
  ] ;
  sh:property [
    sh:path dprod:expirationDate ;
    sh:maxCount 1 ;
    sh:datatype xsd:dateTime ;
    sh:message "expirationDate, if present, must be a single xsd:dateTime value."
  ] ;
.

dprod-contracts-shapes:RejectMixedLifecycleStatusOnDataOfferShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "reject mixed lifecycle status on data offer shape" ;
  dct:description "Keeps lifecycle statuses separate: a dprod:DataOffer uses only dprod:offerLifecycleStatus and must not carry dprod:dataProductLifecycleStatus or dprod:contractLifecycleStatus."@en ;
  sh:targetClass dprod:DataOffer ;
  sh:property [
    sh:path dprod:dataProductLifecycleStatus ;
    sh:maxCount 0 ;
    sh:message "DataOffer must not use dprod:dataProductLifecycleStatus."
  ] ;
  sh:property [
    sh:path dprod:contractLifecycleStatus ;
    sh:maxCount 0 ;
    sh:message "DataOffer must not use dprod:contractLifecycleStatus."
  ] ;
.

dprod-contracts-shapes:RejectMixedLifecycleStatusOnDataContractShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "reject mixed lifecycle status on data contract shape" ;
  dct:description "Keeps lifecycle statuses separate: a dprod:DataContract uses only dprod:contractLifecycleStatus and must not carry dprod:dataProductLifecycleStatus or dprod:offerLifecycleStatus."@en ;
  sh:targetClass dprod:DataContract ;
  sh:property [
    sh:path dprod:dataProductLifecycleStatus ;
    sh:maxCount 0 ;
    sh:message "DataContract must not use dprod:dataProductLifecycleStatus."
  ] ;
  sh:property [
    sh:path dprod:offerLifecycleStatus ;
    sh:maxCount 0 ;
    sh:message "DataContract must not use dprod:offerLifecycleStatus."
  ] ;
.

dprod-contracts-shapes:RejectMixedLifecycleStatusOnDataProductShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "data product lifecycle status separation shape" ;
  dct:description "Keeps lifecycle statuses separate: a dprod:DataProduct uses only dprod:dataProductLifecycleStatus and must not carry dprod:offerLifecycleStatus or dprod:contractLifecycleStatus."@en ;
  sh:targetClass dprod:DataProduct ;
  sh:property [
    sh:path dprod:offerLifecycleStatus ;
    sh:maxCount 0 ;
    sh:message "DataProduct must not use dprod:offerLifecycleStatus."
  ] ;
  sh:property [
    sh:path dprod:contractLifecycleStatus ;
    sh:maxCount 0 ;
    sh:message "DataProduct must not use dprod:contractLifecycleStatus."
  ] ;
.


############################# Operand Shapes #########################


dprod-contracts-shapes:EvaluationContextShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "evaluation context shape" ;
  dct:description "Validates a dprod:EvaluationContext, the input to policy evaluation: it must have exactly one dprod:request graph root, exactly one dprod:state snapshot typed as prov:Entity, exactly one dprod:agent identified by an IRI and typed as odrl:Party, and exactly one dprod:clock xsd:dateTime."@en ;
  sh:targetClass dprod:EvaluationContext ;
  sh:property [
    sh:path dprod:request ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:nodeKind sh:BlankNodeOrIRI ;
    sh:message "An evaluation context must have exactly one dprod:request graph root."
  ] ;
  sh:property [
    sh:path dprod:state ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:nodeKind sh:BlankNodeOrIRI ;
    sh:class prov:Entity ;
    sh:message "An evaluation context must have exactly one immutable dprod:state snapshot, typed as prov:Entity."
  ] ;
  sh:property [
    sh:path dprod:agent ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:nodeKind sh:IRI ;
    sh:class odrl:Party ;
    sh:message "An evaluation context must have exactly one dprod:agent typed as odrl:Party."
  ] ;
  sh:property [
    sh:path dprod:clock ;
    sh:minCount 1 ;
    sh:maxCount 1 ;
    sh:datatype xsd:dateTime ;
    sh:message "An evaluation context must have exactly one dprod:clock xsd:dateTime."
  ] ;
.


dprod-contracts-shapes:LeftOperandShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "left operand shape" ;
  dct:description "Validates every odrl:LeftOperand, whether declared as such or used as the object of odrl:leftOperand. Apart from the built-in operands dprod:currentAgent and odrl:dateTime, each must bind exactly one dprod:operandSource (requestSource, stateSource or contextSource) and exactly one IRI-valued dprod:operandProperty, so the operand resolves to a value in the evaluation context."@en ;
  sh:targetClass odrl:LeftOperand ;
  sh:targetObjectsOf odrl:leftOperand ;
  sh:name "Left Operand Shape" ;
  sh:or (
    [ sh:in (dprod:currentAgent odrl:dateTime) ]
    [
      sh:property [
        sh:path dprod:operandSource ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:in (dprod:requestSource dprod:stateSource dprod:contextSource)
      ]
    ]
  ) ;
  sh:message "Every left operand must declare exactly one dprod:operandSource: requestSource, stateSource, or contextSource." ;
  sh:or (
    [ sh:in (dprod:currentAgent odrl:dateTime) ]
    [
      sh:property [
        sh:path dprod:operandProperty ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI
      ]
    ]
  ) ;
  sh:message "Every left operand must declare exactly one dprod:operandProperty, which must be IRI-valued." ;
.


############################# Rejection Shapes #########################
# Reject unsupported ODRL constructs


dprod-contracts-shapes:RejectRuntimeReferenceShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "obsolete runtime reference rejection shape" ;
  dct:description "Rejects the obsolete dprod:RuntimeReference class. A runtime value is declared as an odrl:LeftOperand with one dprod:operandSource and one dprod:operandProperty binding."@en ;
  sh:targetClass dprod:RuntimeReference ;
  sh:property [
    sh:path rdf:type ;
    sh:maxCount 0 ;
    sh:severity sh:Violation ;
    sh:message "dprod:RuntimeReference is obsolete; declare an odrl:LeftOperand with one source/property binding."
  ] ;
.

dprod-contracts-shapes:RejectOperandPathShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "obsolete operand path rejection shape" ;
  dct:description "Rejects the obsolete dprod:path property. An operand is bound to a single dprod:operandSource and dprod:operandProperty against a normalized source graph, not to a property path."@en ;
  sh:targetSubjectsOf dprod:path ;
  sh:property [
    sh:path dprod:path ;
    sh:maxCount 0 ;
    sh:severity sh:Violation ;
    sh:message "dprod:path is obsolete; normalize the source graph and use dprod:operandSource plus dprod:operandProperty."
  ] ;
.


dprod-contracts-shapes:RejectObsoleteOfferLifecycleStatusSpellingShape
  a sh:NodeShape ;
  rdfs:label "reject obsolete offer lifecycle status spelling" ;
  dct:description "Rejects the obsolete spelling dprod:offerLifeCycleStatus. An offer's lifecycle status uses dprod:offerLifecycleStatus."@en ;
  sh:targetSubjectsOf dprod:offerLifeCycleStatus ;
  sh:property [
    sh:path dprod:offerLifeCycleStatus ;
    sh:maxCount 0 ;
    sh:severity sh:Violation ;
    sh:message "dprod:offerLifeCycleStatus is obsolete; use dprod:offerLifecycleStatus."
  ] ;
.

dprod-contracts-shapes:RejectObsoleteContractLifecycleStatusSpellingShape
  a sh:NodeShape ;
  rdfs:label "reject obsolete contract lifecycle status spelling" ;
  dct:description "Rejects the obsolete spelling dprod:contractLifeCycleStatus. A contract's lifecycle status uses dprod:contractLifecycleStatus."@en ;
  sh:targetSubjectsOf dprod:contractLifeCycleStatus ;
  sh:property [
    sh:path dprod:contractLifeCycleStatus ;
    sh:maxCount 0 ;
    sh:severity sh:Violation ;
    sh:message "dprod:contractLifeCycleStatus is obsolete; use dprod:contractLifecycleStatus."
  ] ;
.


dprod-contracts-shapes:RejectXoneShape
  a sh:NodeShape ;
  rdfs:label "reject xone operator" ;
  dct:description "Rejects the ODRL exclusive-or logical operator odrl:xone, which DPROD contracts do not support. A logical constraint uses odrl:and, odrl:or or dprod:not."@en ;
  sh:targetSubjectsOf odrl:xone ;
  sh:property [
    sh:path odrl:xone ;
    sh:maxCount 0 ;
    sh:severity sh:Violation ;
    sh:message "DPROD contracts do not support xone operator."
  ] ;
.

dprod-contracts-shapes:RejectRemedyShape
  a sh:NodeShape ;
  rdfs:label "reject remedy" ;
  dct:description "Rejects odrl:remedy, which DPROD contracts do not support: DPROD defines no remedy semantics for violated prohibitions."@en ;
  sh:targetSubjectsOf odrl:remedy ;
  sh:property [
    sh:path odrl:remedy ;
    sh:maxCount 0 ;
    sh:severity sh:Violation ;
    sh:message "DPROD contracts do not support odrl:remedy."
  ] ;
.

dprod-contracts-shapes:RejectConsequenceShape
  a sh:NodeShape ;
  rdfs:label "reject consequence" ;
  dct:description "Rejects odrl:consequence, which DPROD contracts do not support: DPROD defines no consequence semantics for unfulfilled duties."@en ;
  sh:targetSubjectsOf odrl:consequence ;
  sh:property [
    sh:path odrl:consequence ;
    sh:maxCount 0 ;
    sh:severity sh:Violation ;
    sh:message "DPROD contracts do not support odrl:consequence."
  ] ;
.

dprod-contracts-shapes:RejectTicketShape
  a sh:NodeShape ;
  rdfs:label "reject ticket policy" ;
  dct:description "Rejects odrl:Ticket policies, which DPROD contracts do not support."@en ;
  sh:targetClass odrl:Ticket ;
  sh:sparql [
    sh:message "DPROD contracts do not support odrl:Ticket." ;
    sh:severity sh:Violation ;
    sh:select """
      SELECT $this WHERE { $this a odrl:Ticket }
    """ ;
  ] ;
.

dprod-contracts-shapes:RejectRequestShape
  a sh:NodeShape ;
  rdfs:label "reject request policy" ;
  dct:description "Rejects odrl:Request policies. DPROD does not yet define Offer-Request-Agreement semantics, so support for requests is deferred."@en ;
  sh:targetClass odrl:Request ;
  sh:sparql [
    sh:message "DPROD contracts reject odrl:Request because Offer-Request-Agreement semantics are undefined; support is deferred." ;
    sh:severity sh:Violation ;
    sh:select """
      SELECT $this WHERE { $this a odrl:Request }
    """ ;
  ] ;
.

dprod-contracts-shapes:PartOfShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "ODRL collection membership shape" ;
  dct:description "Validates ODRL collection membership: odrl:partOf must link an odrl:Asset or odrl:AssetCollection to an odrl:AssetCollection, or an odrl:Party or odrl:PartyCollection to an odrl:PartyCollection."@en ;
  sh:targetSubjectsOf odrl:partOf ;
  sh:or (
    [
      sh:class odrl:Asset ;
      sh:property [ sh:path odrl:partOf ; sh:class odrl:AssetCollection ]
    ]
    [
      sh:class odrl:AssetCollection ;
      sh:property [ sh:path odrl:partOf ; sh:class odrl:AssetCollection ]
    ]
    [
      sh:class odrl:Party ;
      sh:property [ sh:path odrl:partOf ; sh:class odrl:PartyCollection ]
    ]
    [
      sh:class odrl:PartyCollection ;
      sh:property [ sh:path odrl:partOf ; sh:class odrl:PartyCollection ]
    ]
  ) ;
  sh:message "odrl:partOf must link an odrl:Asset to an odrl:AssetCollection or an odrl:Party to an odrl:PartyCollection." ;
.

dprod-contracts-shapes:AssetCollectionShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "explicit asset collection shape" ;
  dct:description "Restricts an odrl:AssetCollection to explicit membership through odrl:partOf. DPROD does not resolve collections from odrl:source or narrow them with odrl:refinement, so neither may be used."@en ;
  sh:targetClass odrl:AssetCollection ;
  sh:property [
    sh:path odrl:source ;
    sh:maxCount 0 ;
    sh:message "DPROD contracts support explicit collection membership only; odrl:source collection resolution is not supported."
  ] ;
  sh:property [
    sh:path odrl:refinement ;
    sh:maxCount 0 ;
    sh:message "DPROD contracts support explicit collection membership only; collection odrl:refinement is not supported."
  ] ;
.

dprod-contracts-shapes:PartyCollectionShape
  a sh:NodeShape ;
  rdfs:isDefinedBy dprod-contracts-shapes: ;
  rdfs:label "explicit party collection shape" ;
  dct:description "Restricts an odrl:PartyCollection to explicit membership through odrl:partOf. DPROD does not resolve collections from odrl:source or narrow them with odrl:refinement, so neither may be used."@en ;
  sh:targetClass odrl:PartyCollection ;
  sh:property [
    sh:path odrl:source ;
    sh:maxCount 0 ;
    sh:message "DPROD contracts support explicit collection membership only; odrl:source collection resolution is not supported."
  ] ;
  sh:property [
    sh:path odrl:refinement ;
    sh:maxCount 0 ;
    sh:message "DPROD contracts support explicit collection membership only; collection odrl:refinement is not supported."
  ] ;
.

dprod-contracts-shapes:RejectObsoleteDprodPartOfShape
  a sh:NodeShape ;
  rdfs:label "reject obsolete dprod:partOf" ;
  dct:description "Rejects the obsolete dprod:partOf property. Collection membership uses odrl:partOf."@en ;
  sh:targetSubjectsOf dprod:partOf ;
  sh:property [
    sh:path dprod:partOf ;
    sh:maxCount 0 ;
    sh:severity sh:Violation ;
    sh:message "dprod:partOf is obsolete; use odrl:partOf."
  ] ;
.

dprod-contracts-shapes:RejectObsoleteDprodMemberOfShape
  a sh:NodeShape ;
  rdfs:label "reject obsolete dprod:memberOf" ;
  dct:description "Rejects the obsolete dprod:memberOf property. Collection membership uses odrl:partOf."@en ;
  sh:targetSubjectsOf dprod:memberOf ;
  sh:property [
    sh:path dprod:memberOf ;
    sh:maxCount 0 ;
    sh:severity sh:Violation ;
    sh:message "dprod:memberOf is obsolete; use odrl:partOf."
  ] ;
.

dprod-contracts-shapes:RejectInheritAllowedShape
  a sh:NodeShape ;
  rdfs:label "reject inheritAllowed" ;
  dct:description "Rejects odrl:inheritAllowed, which DPROD contracts do not support: DPROD defines no policy inheritance."@en ;
  sh:targetSubjectsOf odrl:inheritAllowed ;
  sh:property [
    sh:path odrl:inheritAllowed ;
    sh:maxCount 0 ;
    sh:severity sh:Violation ;
    sh:message "DPROD contracts do not support odrl:inheritAllowed."
  ] ;
.

dprod-contracts-shapes:RejectInheritFromShape
  a sh:NodeShape ;
  rdfs:label "reject inheritFrom" ;
  dct:description "Rejects odrl:inheritFrom, which DPROD contracts do not support: DPROD defines no policy inheritance."@en ;
  sh:targetSubjectsOf odrl:inheritFrom ;
  sh:property [
    sh:path odrl:inheritFrom ;
    sh:maxCount 0 ;
    sh:severity sh:Violation ;
    sh:message "DPROD contracts do not support odrl:inheritFrom."
  ] ;
.
