<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

/**
 * Capability definitions for local_kid.
 *
 * @package    local_kid
 */

defined('MOODLE_INTERNAL') || die();

$capabilities = [

    // ── Socle commun : accéder au plugin et consulter ──
    'local/kid:view' => [
        'captype'      => 'read',
        'contextlevel' => CONTEXT_SYSTEM,
        'archetypes'   => [],
    ],

    // ── Saisie / validation / finalisation / réouverture, PAR DOMAINE ──
    // (une seule capability par domaine couvre saisir + valider + finaliser + rouvrir)
    'local/kid:evaluate_evaluation' => [
        'captype'      => 'write',
        'contextlevel' => CONTEXT_SYSTEM,
        'riskbitmask'  => RISK_DATALOSS,
        'archetypes'   => [],
    ],
    'local/kid:evaluate_stage' => [
        'captype'      => 'write',
        'contextlevel' => CONTEXT_SYSTEM,
        'riskbitmask'  => RISK_DATALOSS,
        'archetypes'   => [],
    ],
    'local/kid:evaluate_capp' => [
        'captype'      => 'write',
        'contextlevel' => CONTEXT_SYSTEM,
        'riskbitmask'  => RISK_DATALOSS,
        'archetypes'   => [],
    ],

    // ── Rattachement + synchronisation d'un devoir Moodle (évaluations) ──
    'local/kid:sync_moodle' => [
        'captype'      => 'write',
        'contextlevel' => CONTEXT_SYSTEM,
        'archetypes'   => [],
    ],

    // ── Publication aux élèves, PAR DOMAINE ──
    'local/kid:publish_evaluation' => [
        'captype'      => 'write',
        'contextlevel' => CONTEXT_SYSTEM,
        'riskbitmask'  => RISK_PERSONAL,
        'archetypes'   => [],
    ],
    'local/kid:publish_stage' => [
        'captype'      => 'write',
        'contextlevel' => CONTEXT_SYSTEM,
        'riskbitmask'  => RISK_PERSONAL,
        'archetypes'   => [],
    ],
    'local/kid:publish_capp' => [
        'captype'      => 'write',
        'contextlevel' => CONTEXT_SYSTEM,
        'riskbitmask'  => RISK_PERSONAL,
        'archetypes'   => [],
    ],

    // ── Administration des référentiels, PAR DOMAINE ──
    'local/kid:manage_evaluation' => [
        'captype'      => 'write',
        'contextlevel' => CONTEXT_SYSTEM,
        'riskbitmask'  => RISK_DATALOSS | RISK_CONFIG,
        'archetypes'   => [],
    ],
    'local/kid:manage_stage' => [
        'captype'      => 'write',
        'contextlevel' => CONTEXT_SYSTEM,
        'riskbitmask'  => RISK_DATALOSS | RISK_CONFIG,
        'archetypes'   => [],
    ],
    'local/kid:manage_capp' => [
        'captype'      => 'write',
        'contextlevel' => CONTEXT_SYSTEM,
        'riskbitmask'  => RISK_DATALOSS | RISK_CONFIG,
        'archetypes'   => [],
    ],

    // ── Administration générale (compétences, niveaux, promotions/cohortes, suppressions) ──
    'local/kid:manage' => [
        'captype'      => 'write',
        'contextlevel' => CONTEXT_SYSTEM,
        'riskbitmask'  => RISK_DATALOSS | RISK_CONFIG,
        'archetypes'   => [],
    ],

    // ── Export ADESI (Admin seul) ──
    'local/kid:export_adesi' => [
        'captype'      => 'read',
        'contextlevel' => CONTEXT_SYSTEM,
        'riskbitmask'  => RISK_PERSONAL,
        'archetypes'   => [],
    ],

    // ── Choisir la promotion affichée (sélecteur global) ──
    'local/kid:selectpromotion' => [
        'captype'      => 'read',
        'contextlevel' => CONTEXT_SYSTEM,
        'archetypes'   => [],
    ],

    // ── Prévisualiser le dossier d'un autre élève (rôles internes) ──
    'local/kid:viewany' => [
        'captype'      => 'read',
        'contextlevel' => CONTEXT_SYSTEM,
        'riskbitmask'  => RISK_PERSONAL,
        'archetypes'   => [],
    ],

    // ── Élève : voir son propre dossier publié ──
    'local/kid:viewown' => [
        'captype'      => 'read',
        'contextlevel' => CONTEXT_SYSTEM,
        'archetypes'   => [],
    ],

    // ── Consulter le journal d'audit (données nominatives) ──
    'local/kid:viewjournal' => [
        'captype'      => 'read',
        'contextlevel' => CONTEXT_SYSTEM,
        'riskbitmask'  => RISK_PERSONAL,
        'archetypes'   => [],
    ],

    // ── Consulter l'annuaire des élèves (recherche nominative) ──
    'local/kid:viewannuaire' => [
        'captype'      => 'read',
        'contextlevel' => CONTEXT_SYSTEM,
        'riskbitmask'  => RISK_PERSONAL,
        'archetypes'   => [],
    ],

    // ── Gérer ses tableaux de bord favoris (Comparateur de bilans) ──
    'local/kid:managedashboardfavourites' => [
        'captype'      => 'write',
        'contextlevel' => CONTEXT_SYSTEM,
        'archetypes'   => [],
    ],
];
