@prefix : <https://ontology.inferal.com/modules/insurance-market/> .
@prefix ci: <https://ontology.inferal.com/modules/company-intelligence/> .
@prefix conf: <https://ontology.inferal.com/modules/confidence/> .
@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#> .

:InsuranceRoleConceptShape
    a sh:NodeShape ;
    rdfs:label "insurance role concept shape" ;
    rdfs:comment "Requires a role value to be a SKOS concept in the insurance role scheme." ;
    sh:class skos:Concept ;
    sh:property [ sh:path skos:inScheme ; sh:hasValue :InsuranceRoleScheme ] .

:ParticipantFormConceptShape
    a sh:NodeShape ;
    rdfs:label "participant form concept shape" ;
    rdfs:comment "Requires a participant-form value to be a SKOS concept in the participant form scheme." ;
    sh:class skos:Concept ;
    sh:property [ sh:path skos:inScheme ; sh:hasValue :ParticipantFormScheme ] .

:InsuranceActionConceptShape
    a sh:NodeShape ;
    rdfs:label "insurance action concept shape" ;
    rdfs:comment "Requires an authorized-action value to be a SKOS concept in the insurance action scheme." ;
    sh:class skos:Concept ;
    sh:property [ sh:path skos:inScheme ; sh:hasValue :InsuranceActionScheme ] .

:InsuranceRoleAssignmentShape
    a sh:NodeShape ;
    rdfs:label "insurance role assignment shape" ;
    rdfs:comment "Validates a sourced role assignment with exactly one player, role concept, and context, plus optional representation, jurisdiction, validity, and confidence." ;
    sh:targetClass :InsuranceRoleAssignment ;
    sh:property [ sh:path :rolePlayer ; sh:nodeKind sh:BlankNodeOrIRI ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :roleType ; sh:node :InsuranceRoleConceptShape ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :roleContext ; sh:nodeKind sh:BlankNodeOrIRI ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :representedParty ; sh:nodeKind sh:BlankNodeOrIRI ; sh:maxCount 1 ] ;
    sh:property [ sh:path :jurisdiction ; sh:class ci:Jurisdiction ] ;
    sh:property [ sh:path ci:source ; sh:class ci:Source ; sh:minCount 1 ] ;
    sh:property [ sh:path ci:validFrom ; sh:datatype xsd:date ; sh:maxCount 1 ] ;
    sh:property [ sh:path ci:validThrough ; sh:datatype xsd:date ; sh:maxCount 1 ] ;
    sh:property [ sh:path ci:confidenceAssessment ; sh:class conf:ConfidenceAssessment ; sh:maxCount 1 ] ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "validFrom must not be later than validThrough." ;
        sh:select """
            PREFIX ci: <https://ontology.inferal.com/modules/company-intelligence/>
            SELECT $this WHERE {
              $this ci:validFrom ?from ; ci:validThrough ?through .
              FILTER (?from > ?through)
            }
        """ ;
    ] .

:InsurancePlacementShape
    a sh:NodeShape ;
    rdfs:label "insurance placement shape" ;
    rdfs:comment "Validates a named, sourced insurance placement that may involve multiple offerings, resulting policies, and jurisdictions." ;
    sh:targetClass :InsurancePlacement ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ] ;
    sh:property [ sh:path :placementOffering ; sh:class :InsuranceOffering ] ;
    sh:property [ sh:path :resultingPolicy ; sh:class :InsurancePolicy ] ;
    sh:property [ sh:path :jurisdiction ; sh:class ci:Jurisdiction ] ;
    sh:property [ sh:path ci:source ; sh:class ci:Source ; sh:minCount 1 ] .

:InsurancePolicyShape
    a sh:NodeShape ;
    rdfs:label "insurance policy shape" ;
    rdfs:comment "Validates a named, sourced policy anchor that may carry multiple source-local identifiers and jurisdictions." ;
    sh:targetClass :InsurancePolicy ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ] ;
    sh:property [ sh:path :policyIdentifier ; sh:datatype xsd:string ] ;
    sh:property [ sh:path :jurisdiction ; sh:class ci:Jurisdiction ] ;
    sh:property [ sh:path ci:source ; sh:class ci:Source ; sh:minCount 1 ] .

:InsuranceOfferingShape
    a sh:NodeShape ;
    rdfs:label "insurance offering shape" ;
    rdfs:comment "Validates a named insurance product, service, placement, administration, or risk-capacity offering with supporting evidence." ;
    sh:targetClass :InsuranceOffering ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ] ;
    sh:property [ sh:path ci:source ; sh:class ci:Source ; sh:minCount 1 ] .

:DelegatedAuthorityShape
    a sh:NodeShape ;
    rdfs:label "delegated authority shape" ;
    rdfs:comment "Validates explicit delegated authority with distinct parties, one or more evidence instruments, at least one action, one or more jurisdictions, and optional roles, scope, dates, and confidence." ;
    sh:targetClass :DelegatedAuthority ;
    sh:property [ sh:path :authorityGrantor ; sh:nodeKind sh:BlankNodeOrIRI ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :authorityGrantee ; sh:nodeKind sh:BlankNodeOrIRI ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :authorityInstrument ; sh:class ci:Source ; sh:minCount 1 ] ;
    sh:property [ sh:path :authorizedAction ; sh:node :InsuranceActionConceptShape ; sh:minCount 1 ] ;
    sh:property [ sh:path :authorizedRole ; sh:node :InsuranceRoleConceptShape ] ;
    sh:property [ sh:path :authorityScope ; sh:datatype xsd:string ] ;
    sh:property [ sh:path :jurisdiction ; sh:class ci:Jurisdiction ; sh:minCount 1 ] ;
    sh:property [ sh:path ci:source ; sh:class ci:Source ; sh:minCount 1 ] ;
    sh:property [ sh:path ci:validFrom ; sh:datatype xsd:date ; sh:maxCount 1 ] ;
    sh:property [ sh:path ci:validThrough ; sh:datatype xsd:date ; sh:maxCount 1 ] ;
    sh:property [ sh:path ci:confidenceAssessment ; sh:class conf:ConfidenceAssessment ; sh:maxCount 1 ] ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "The authority grantor and grantee must be different resources." ;
        sh:select """
            PREFIX insm: <https://ontology.inferal.com/modules/insurance-market/>
            SELECT $this WHERE {
              $this insm:authorityGrantor ?party ; insm:authorityGrantee ?party .
            }
        """ ;
    ] ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "validFrom must not be later than validThrough." ;
        sh:select """
            PREFIX ci: <https://ontology.inferal.com/modules/company-intelligence/>
            SELECT $this WHERE {
              $this ci:validFrom ?from ; ci:validThrough ?through .
              FILTER (?from > ?through)
            }
        """ ;
    ] .

:RiskParticipationShape
    a sh:NodeShape ;
    rdfs:label "risk participation shape" ;
    rdfs:comment "Validates a sourced risk participation with exactly one party, context, and role, plus optional written and retained shares, jurisdiction, validity, and confidence." ;
    sh:targetClass :RiskParticipation ;
    sh:property [ sh:path :participatingParty ; sh:nodeKind sh:BlankNodeOrIRI ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :participationContext ; sh:nodeKind sh:BlankNodeOrIRI ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :riskRole ; sh:node :InsuranceRoleConceptShape ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :writtenShare ; sh:datatype xsd:decimal ; sh:minInclusive 0 ; sh:maxInclusive 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :retainedShare ; sh:datatype xsd:decimal ; sh:minInclusive 0 ; sh:maxInclusive 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :jurisdiction ; sh:class ci:Jurisdiction ] ;
    sh:property [ sh:path ci:source ; sh:class ci:Source ; sh:minCount 1 ] ;
    sh:property [ sh:path ci:validFrom ; sh:datatype xsd:date ; sh:maxCount 1 ] ;
    sh:property [ sh:path ci:validThrough ; sh:datatype xsd:date ; sh:maxCount 1 ] ;
    sh:property [ sh:path ci:confidenceAssessment ; sh:class conf:ConfidenceAssessment ; sh:maxCount 1 ] ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "retainedShare must not be greater than writtenShare." ;
        sh:select """
            PREFIX insm: <https://ontology.inferal.com/modules/insurance-market/>
            SELECT $this WHERE {
              $this insm:writtenShare ?written ; insm:retainedShare ?retained .
              FILTER (?retained > ?written)
            }
        """ ;
    ] ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "validFrom must not be later than validThrough." ;
        sh:select """
            PREFIX ci: <https://ontology.inferal.com/modules/company-intelligence/>
            SELECT $this WHERE {
              $this ci:validFrom ?from ; ci:validThrough ?through .
              FILTER (?from > ?through)
            }
        """ ;
    ] .

:RiskTransferShape
    a sh:NodeShape ;
    rdfs:label "risk transfer shape" ;
    rdfs:comment "Validates a sourced risk transfer with distinct transferor and transferee, one context, and optional transferred share, jurisdiction, validity, and confidence." ;
    sh:targetClass :RiskTransfer ;
    sh:property [ sh:path :transferor ; sh:nodeKind sh:BlankNodeOrIRI ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :transferee ; sh:nodeKind sh:BlankNodeOrIRI ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :transferContext ; sh:nodeKind sh:BlankNodeOrIRI ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :transferredShare ; sh:datatype xsd:decimal ; sh:minInclusive 0 ; sh:maxInclusive 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :jurisdiction ; sh:class ci:Jurisdiction ] ;
    sh:property [ sh:path ci:source ; sh:class ci:Source ; sh:minCount 1 ] ;
    sh:property [ sh:path ci:validFrom ; sh:datatype xsd:date ; sh:maxCount 1 ] ;
    sh:property [ sh:path ci:validThrough ; sh:datatype xsd:date ; sh:maxCount 1 ] ;
    sh:property [ sh:path ci:confidenceAssessment ; sh:class conf:ConfidenceAssessment ; sh:maxCount 1 ] ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "The risk transferor and transferee must be different resources." ;
        sh:select """
            PREFIX insm: <https://ontology.inferal.com/modules/insurance-market/>
            SELECT $this WHERE {
              $this insm:transferor ?party ; insm:transferee ?party .
            }
        """ ;
    ] ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "validFrom must not be later than validThrough." ;
        sh:select """
            PREFIX ci: <https://ontology.inferal.com/modules/company-intelligence/>
            SELECT $this WHERE {
              $this ci:validFrom ?from ; ci:validThrough ?through .
              FILTER (?from > ?through)
            }
        """ ;
    ] .

:ParticipantClassificationShape
    a sh:NodeShape ;
    rdfs:label "participant classification shape" ;
    rdfs:comment "Validates an evidence-bearing participant-form classification with exactly one party and form plus optional jurisdictions, validity, and confidence." ;
    sh:targetClass :ParticipantClassification ;
    sh:property [ sh:path :classifiedParticipant ; sh:nodeKind sh:BlankNodeOrIRI ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :participantForm ; sh:node :ParticipantFormConceptShape ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path :jurisdiction ; sh:class ci:Jurisdiction ] ;
    sh:property [ sh:path ci:source ; sh:class ci:Source ; sh:minCount 1 ] ;
    sh:property [ sh:path ci:validFrom ; sh:datatype xsd:date ; sh:maxCount 1 ] ;
    sh:property [ sh:path ci:validThrough ; sh:datatype xsd:date ; sh:maxCount 1 ] ;
    sh:property [ sh:path ci:confidenceAssessment ; sh:class conf:ConfidenceAssessment ; sh:maxCount 1 ] ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "validFrom must not be later than validThrough." ;
        sh:select """
            PREFIX ci: <https://ontology.inferal.com/modules/company-intelligence/>
            SELECT $this WHERE {
              $this ci:validFrom ?from ; ci:validThrough ?through .
              FILTER (?from > ?through)
            }
        """ ;
    ] .
