@prefix celine: <https://w3id.org/celine-eu#> .
@prefix sh:     <http://www.w3.org/ns/shacl#> .
@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd:    <http://www.w3.org/2001/XMLSchema#> .
@prefix dct:    <http://purl.org/dc/terms/> .
@prefix time:   <http://www.w3.org/2006/time#> .
@prefix skos:   <http://www.w3.org/2004/02/skos/core#> .

@prefix peco:   <https://purl.org/peco/peco-core#> .
@prefix saref:  <https://saref.etsi.org/core/> .
@prefix sosa:   <http://www.w3.org/ns/sosa/> .
@prefix bigg:   <https://w3id.org/bigg/ontology#> .

################################################################################
# CELINE SHACL Profile (lean, orchestration-only)
################################################################################

celine:CommunityContextShape
    a sh:NodeShape ;
    sh:targetClass celine:CommunityContext ;
    rdfs:label "CommunityContext constraints" ;
    sh:property [
        sh:path celine:hasCommunity ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class peco:EnergyCommunity ;
    ] ;
    sh:property [
        sh:path celine:usesAsset ;
        sh:nodeKind sh:IRI ;
        sh:class saref:Device ;
        sh:minCount 0 ;
    ] ;
    sh:property [
        sh:path celine:hasSimulation ;
        sh:nodeKind sh:IRI ;
        sh:class celine:Simulation ;
        sh:minCount 0 ;
    ] ;
    sh:property [
        sh:path celine:hasCommitment ;
        sh:nodeKind sh:IRI ;
        sh:class celine:FlexibilityCommitment ;
        sh:minCount 0 ;
    ] ;
    sh:property [
        sh:path celine:hasSettlementRun ;
        sh:nodeKind sh:IRI ;
        sh:class celine:SettlementRun ;
        sh:minCount 0 ;
    ] ;
    sh:property [
        sh:path celine:hasEnvelope ;
        sh:nodeKind sh:IRI ;
        sh:class celine:FlexibilityEnvelope ;
        sh:minCount 0 ;
    ] .

celine:ScenarioShape
    a sh:NodeShape ;
    sh:targetClass celine:Scenario ;
    rdfs:label "Scenario constraints" ;
    sh:property [
        sh:path rdfs:label ;
        sh:datatype xsd:string ;
        sh:minCount 0 ;
    ] ;
    sh:property [
        sh:path dct:description ;
        sh:datatype xsd:string ;
        sh:minCount 0 ;
    ] ;
    sh:property [
        sh:path celine:hasTimeInterval ;
        sh:nodeKind sh:IRI ;
        sh:class time:Interval ;
        sh:minCount 0 ;
        sh:maxCount 1 ;
    ] .

celine:SimulationShape
    a sh:NodeShape ;
    sh:targetClass celine:Simulation ;
    rdfs:label "Simulation constraints" ;
    sh:property [
        sh:path celine:hasScenario ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class celine:Scenario ;
    ] ;
    sh:property [
        sh:path celine:hasSimulationRun ;
        sh:nodeKind sh:IRI ;
        sh:class celine:SimulationRun ;
        sh:minCount 0 ;
    ] .

celine:SimulationRunShape
    a sh:NodeShape ;
    sh:targetClass celine:SimulationRun ;
    rdfs:label "SimulationRun constraints" ;
    sh:property [
        sh:path celine:usesDataset ;
        sh:minCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class celine:DatasetReference ;
    ] ;
    sh:property [
        sh:path celine:producesDataset ;
        sh:minCount 0 ;
        sh:nodeKind sh:IRI ;
        sh:class celine:DatasetReference ;
    ] ;
    sh:property [
        sh:path celine:hasKPIEvaluation ;
        sh:minCount 0 ;
        sh:nodeKind sh:IRI ;
        sh:class celine:KPIEvaluation ;
    ] ;
    sh:property [
        sh:path celine:usesObservation ;
        sh:minCount 0 ;
        sh:nodeKind sh:IRI ;
        sh:class sosa:Observation ;
    ] .

celine:DatasetReferenceShape
    a sh:NodeShape ;
    sh:targetClass celine:DatasetReference ;
    rdfs:label "DatasetReference constraints" ;
    sh:property [
        sh:path dct:identifier ;
        sh:datatype xsd:string ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
    ] ;
    sh:property [
        sh:path dct:source ;
        sh:nodeKind sh:IRI ;
        sh:minCount 0 ;
    ] .

celine:KPIEvaluationShape
    a sh:NodeShape ;
    sh:targetClass celine:KPIEvaluation ;
    rdfs:label "KPIEvaluation constraints" ;
    sh:property [
        sh:path celine:evaluatesKPI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class bigg:KPI ;
    ] ;
    sh:property [
        sh:path rdf:value ;
        sh:minCount 0 ;
        sh:or (
            [ sh:datatype xsd:decimal ]
            [ sh:datatype xsd:double ]
            [ sh:datatype xsd:string ]
        ) ;
    ] .

################################################################################
# Flexibility Commitment shapes  (new in v0.4)
################################################################################

celine:FlexibilityCommitmentShape
    a sh:NodeShape ;
    sh:targetClass celine:FlexibilityCommitment ;
    rdfs:label "FlexibilityCommitment constraints" ;
    sh:property [
        sh:path celine:committedBy ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class peco:Energy_community_member ;
    ] ;
    sh:property [
        sh:path celine:onPOD ;
        sh:minCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class peco:Electric_POD ;
    ] ;
    sh:property [
        sh:path celine:hasCommitmentMode ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class skos:Concept ;
    ] ;
    sh:property [
        sh:path celine:hasFlexibilityDirection ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class skos:Concept ;
    ] ;
    sh:property [
        sh:path celine:targetFlexibility ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:datatype xsd:decimal ;
        sh:minExclusive 0 ;
    ] ;
    sh:property [
        sh:path celine:hasTimeInterval ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class time:Interval ;
    ] ;
    sh:property [
        sh:path celine:generatesCredit ;
        sh:minCount 0 ;
        sh:nodeKind sh:IRI ;
        sh:class celine:FlexibilityCredit ;
    ] ;
    sh:property [
        sh:path celine:withinEnvelope ;
        sh:minCount 0 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class celine:FlexibilityEnvelope ;
    ] .

celine:FlexibilityCreditShape
    a sh:NodeShape ;
    sh:targetClass celine:FlexibilityCredit ;
    rdfs:label "FlexibilityCredit constraints" ;
    sh:property [
        sh:path celine:earnedBy ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class peco:Energy_community_member ;
    ] ;
    sh:property [
        sh:path celine:creditFor ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class celine:FlexibilityCommitment ;
    ] ;
    sh:property [
        sh:path celine:creditAmount ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:datatype xsd:decimal ;
        sh:minInclusive 0 ;
    ] ;
    sh:property [
        sh:path celine:evidencedBy ;
        sh:minCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class sosa:Observation ;
    ] .

################################################################################
# Settlement shapes  (new in v0.4)
################################################################################

celine:SettlementRunShape
    a sh:NodeShape ;
    sh:targetClass celine:SettlementRun ;
    rdfs:label "SettlementRun constraints" ;
    sh:property [
        sh:path celine:settlesContext ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class celine:CommunityContext ;
    ] ;
    sh:property [
        sh:path celine:hasTimeInterval ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class time:Interval ;
    ] ;
    sh:property [
        sh:path celine:conversionRate ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:datatype xsd:decimal ;
        sh:minExclusive 0 ;
    ] ;
    sh:property [
        sh:path celine:currency ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:datatype xsd:string ;
        sh:minLength 3 ;
        sh:maxLength 3 ;
    ] ;
    sh:property [
        sh:path celine:hasCostItem ;
        sh:minCount 0 ;
        sh:nodeKind sh:IRI ;
        sh:class celine:CostItem ;
    ] ;
    sh:property [
        sh:path celine:hasRedistributionResult ;
        sh:minCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class celine:RedistributionResult ;
    ] .

celine:CostItemShape
    a sh:NodeShape ;
    sh:targetClass celine:CostItem ;
    rdfs:label "CostItem constraints" ;
    sh:property [
        sh:path celine:hasCostType ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class skos:Concept ;
    ] ;
    sh:property [
        sh:path dct:description ;
        sh:datatype xsd:string ;
        sh:minCount 0 ;
    ] ;
    sh:property [
        sh:path celine:costAmount ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:datatype xsd:decimal ;
        sh:minInclusive 0 ;
    ] .

celine:RedistributionResultShape
    a sh:NodeShape ;
    sh:targetClass celine:RedistributionResult ;
    rdfs:label "RedistributionResult constraints" ;
    sh:property [
        sh:path celine:resultFor ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class peco:Energy_community_member ;
    ] ;
    sh:property [
        sh:path celine:creditBalance ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:datatype xsd:decimal ;
        sh:minInclusive 0 ;
    ] ;
    sh:property [
        sh:path celine:grossAmount ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:datatype xsd:decimal ;
    ] ;
    sh:property [
        sh:path celine:costDeduction ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:datatype xsd:decimal ;
        sh:minInclusive 0 ;
    ] ;
    sh:property [
        sh:path celine:netAmount ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:datatype xsd:decimal ;
    ] .

################################################################################
# Flexibility Envelope shapes  (new in v0.4)
################################################################################

celine:FlexibilityEnvelopeShape
    a sh:NodeShape ;
    sh:targetClass celine:FlexibilityEnvelope ;
    rdfs:label "FlexibilityEnvelope constraints" ;
    sh:property [
        sh:path celine:envelopeFor ;
        sh:minCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class peco:Electric_POD ;
    ] ;
    sh:property [
        sh:path celine:maxFlexUp ;
        sh:minCount 0 ;
        sh:maxCount 1 ;
        sh:datatype xsd:decimal ;
        sh:minInclusive 0 ;
    ] ;
    sh:property [
        sh:path celine:maxFlexDown ;
        sh:minCount 0 ;
        sh:maxCount 1 ;
        sh:datatype xsd:decimal ;
        sh:minInclusive 0 ;
    ] ;
    sh:property [
        sh:path celine:availableEnergy ;
        sh:minCount 0 ;
        sh:maxCount 1 ;
        sh:datatype xsd:decimal ;
        sh:minInclusive 0 ;
    ] ;
    sh:property [
        sh:path celine:hasAvailabilityWindow ;
        sh:minCount 0 ;
        sh:nodeKind sh:IRI ;
        sh:class time:Interval ;
    ] ;
    sh:property [
        sh:path celine:hasConstraint ;
        sh:minCount 0 ;
        sh:nodeKind sh:IRI ;
        sh:class celine:FlexibilityConstraint ;
    ] .

################################################################################
# Flexibility Constraint shapes  (new in v0.4)
################################################################################

celine:FlexibilityConstraintShape
    a sh:NodeShape ;
    sh:targetClass celine:FlexibilityConstraint ;
    rdfs:label "FlexibilityConstraint constraints" ;
    sh:property [
        sh:path celine:hasConstraintType ;
        sh:minCount 1 ;
        sh:nodeKind sh:IRI ;
        sh:class skos:Concept ;
    ] ;
    sh:property [
        sh:path celine:minActivationDuration ;
        sh:minCount 0 ;
        sh:maxCount 1 ;
        sh:datatype xsd:duration ;
    ] ;
    sh:property [
        sh:path celine:maxActivationDuration ;
        sh:minCount 0 ;
        sh:maxCount 1 ;
        sh:datatype xsd:duration ;
    ] ;
    sh:property [
        sh:path celine:minNotificationTime ;
        sh:minCount 0 ;
        sh:maxCount 1 ;
        sh:datatype xsd:duration ;
    ] ;
    sh:property [
        sh:path celine:minRecoveryTime ;
        sh:minCount 0 ;
        sh:maxCount 1 ;
        sh:datatype xsd:duration ;
    ] ;
    sh:property [
        sh:path celine:maxActivationsPerDay ;
        sh:minCount 0 ;
        sh:maxCount 1 ;
        sh:datatype xsd:integer ;
        sh:minInclusive 1 ;
    ] .

################################################################################
# TIME interval minimal constraints (carried from v0.3)
################################################################################

celine:TimeIntervalShape
    a sh:NodeShape ;
    sh:targetClass time:Interval ;
    rdfs:label "time:Interval minimal constraints" ;
    sh:property [
        sh:path time:hasBeginning ;
        sh:nodeKind sh:IRI ;
        sh:minCount 0 ;
        sh:maxCount 1 ;
    ] ;
    sh:property [
        sh:path time:hasEnd ;
        sh:nodeKind sh:IRI ;
        sh:minCount 0 ;
        sh:maxCount 1 ;
    ] .
