@prefix sh:     <http://www.w3.org/ns/shacl#> .
@prefix xsd:    <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ao:   <https://arnwaldn.github.io/agent-owl/ontology/audit#> .

# =============================================================================
# Agent Owl SHACL Shapes — Validation Rules
# Tier 1: Core (all AI systems)
# Tier 2: High-Risk (Annex IV requirements, Art. 6)
# =============================================================================

# =============================================================================
# TIER 1 — CORE SHAPES (all AI systems)
# =============================================================================

ao:AISystemCoreShape a sh:NodeShape ;
    sh:targetClass ao:AISystem ;
    rdfs:label "AI System — Core validation"@fr ;
    rdfs:comment "Validation de base pour tout systeme d'IA enregistre."@fr ;

    sh:property [
        sh:path ao:systemName ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:datatype xsd:string ;
        sh:minLength 1 ;
        sh:message "Un systeme d'IA doit avoir exactement un nom (systemName)."@fr ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path ao:hasRiskLevel ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:class ao:RiskLevel ;
        sh:message "Un systeme d'IA doit avoir exactement un niveau de risque (hasRiskLevel)."@fr ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path ao:hasComplianceStatus ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:class ao:ComplianceStatus ;
        sh:message "Un systeme d'IA doit avoir exactement un statut de conformite (hasComplianceStatus)."@fr ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path ao:intendedPurpose ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:message "La finalite prevue (intendedPurpose) est recommandee pour tout systeme d'IA."@fr ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path ao:retentionMinMonths ;
        sh:minInclusive 6 ;
        sh:datatype xsd:positiveInteger ;
        sh:message "La retention minimale des journaux doit etre d'au moins 6 mois (Art. 19)."@fr ;
        sh:severity sh:Violation
    ] .


ao:IncidentCoreShape a sh:NodeShape ;
    sh:targetClass ao:Incident ;
    rdfs:label "Incident — Core validation"@fr ;

    sh:property [
        sh:path ao:involvesSystem ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:class ao:AISystem ;
        sh:message "Un incident doit impliquer exactement un systeme d'IA (involvesSystem)."@fr ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path ao:hasIncidentSeverity ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:class ao:IncidentSeverity ;
        sh:message "Un incident doit avoir exactement une severite (hasIncidentSeverity)."@fr ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path ao:incidentDescription ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:minLength 1 ;
        sh:message "Un incident doit avoir une description (incidentDescription)."@fr ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path ao:incidentTimestamp ;
        sh:minCount 1 ;
        sh:datatype xsd:dateTime ;
        sh:message "Un incident doit avoir un horodatage (incidentTimestamp)."@fr ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path ao:reportingDeadline ;
        sh:minCount 1 ;
        sh:datatype xsd:dateTime ;
        sh:message "Un incident doit avoir une date limite de declaration (reportingDeadline, Art. 73)."@fr ;
        sh:severity sh:Warning
    ] .


ao:DatasetCoreShape a sh:NodeShape ;
    sh:targetClass ao:Dataset ;
    rdfs:label "Dataset — Core validation"@fr ;

    sh:property [
        sh:path ao:datasetName ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:datatype xsd:string ;
        sh:minLength 1 ;
        sh:message "Un jeu de donnees doit avoir un nom (datasetName)."@fr ;
        sh:severity sh:Violation
    ] .


ao:ModelVersionCoreShape a sh:NodeShape ;
    sh:targetClass ao:ModelVersion ;
    rdfs:label "Model Version — Core validation"@fr ;

    sh:property [
        sh:path ao:modelVersionTag ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:datatype xsd:string ;
        sh:minLength 1 ;
        sh:message "Une version de modele doit avoir un tag (modelVersionTag)."@fr ;
        sh:severity sh:Violation
    ] .


# =============================================================================
# TIER 2 — HIGH-RISK SHAPES (Annex IV, Art. 6 systems)
# NOTE: These shapes do NOT use sh:targetClass. They are activated
# programmatically by the validator for high-risk systems only.
# =============================================================================

ao:AISystemHighRiskShape a sh:NodeShape ;
    rdfs:label "AI System — High-Risk (Annexe IV)"@fr ;
    rdfs:comment "Champs obligatoires pour la documentation technique des systemes a haut risque."@fr ;

    sh:property [
        sh:path ao:annexIV_generalDescription ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:minLength 10 ;
        sh:message "Documentation technique : description generale requise (Annexe IV, pt. 1)."@fr ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path ao:annexIV_oversightMeasures ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:message "Mesures de supervision humaine requises (Annexe IV, pt. 6, Art. 14)."@fr ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path ao:annexIV_cybersecurityMeasures ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:message "Mesures de cybersecurite requises (Annexe IV, pt. 7, Art. 15)."@fr ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path ao:annexIV_foreseeMisuse ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:message "Mesusages previsibles requis (Annexe IV, pt. 4)."@fr ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path ao:annexIV_componentDescription ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:message "Description des composants requise (Annexe IV, pt. 2)."@fr ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path ao:annexIV_developmentProcess ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:message "Processus de developpement requis (Annexe IV, pt. 3)."@fr ;
        sh:severity sh:Warning
    ] .


ao:ModelVersionHighRiskShape a sh:NodeShape ;
    rdfs:label "Model Version — High-Risk (Annexe IV)"@fr ;

    sh:property [
        sh:path ao:annexIV_performanceDescription ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:message "Description des performances requise (Annexe IV, pt. 4)."@fr ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path ao:annexIV_knownLimitations ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:message "Limites connues requises (Annexe IV, pt. 4)."@fr ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path ao:annexIV_accuracyMetrics ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:message "Metriques de precision requises (Annexe IV, pt. 7)."@fr ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path ao:annexIV_robustnessTests ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:message "Tests de robustesse requis (Annexe IV, pt. 7)."@fr ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path ao:annexIV_designChoices ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:message "Choix de conception requis (Annexe IV, pt. 3)."@fr ;
        sh:severity sh:Warning
    ] .


ao:DatasetHighRiskShape a sh:NodeShape ;
    rdfs:label "Dataset — High-Risk (Annexe IV)"@fr ;

    sh:property [
        sh:path ao:annexIV_dataGovernance ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:message "Gouvernance des donnees requise (Annexe IV, pt. 5, Art. 10)."@fr ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path ao:annexIV_dataOrigin ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:message "Origine des donnees requise (Annexe IV, pt. 5)."@fr ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path ao:annexIV_dataBiasAssessment ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:message "Evaluation des biais requise (Annexe IV, pt. 5)."@fr ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path ao:annexIV_dataPreparation ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
        sh:message "Preparation des donnees requise (Annexe IV, pt. 5)."@fr ;
        sh:severity sh:Warning
    ] .
