<?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.

namespace local_kid\event;

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

/**
 * Fired on link/unlink/resync of a promotion↔cohort relationship.
 *
 * `objectid` is the promotion id (objecttable local_kid_promotion); the
 * cohort id and per-action counts travel in `other`, since this event isn't
 * about the cohort record itself.
 */
class cohort_synced extends \core\event\base {

    protected function init() {
        $this->data['crud'] = 'u';
        $this->data['edulevel'] = self::LEVEL_OTHER;
        $this->data['objecttable'] = 'local_kid_promotion';
    }

    public static function get_name() {
        return get_string('event_cohort_synced', 'local_kid');
    }

    public function get_description() {
        $action = $this->other['action'] ?? 'synced';
        $cohortid = $this->other['cohortid'] ?? 0;
        $added = $this->other['addedcount'] ?? 0;
        $removed = $this->other['removedcount'] ?? 0;
        return "The user with id '{$this->userid}' {$action} cohort '{$cohortid}' on promotion " .
            "'{$this->objectid}' (added={$added}, removed={$removed}).";
    }

    public function get_url() {
        return new \moodle_url('/local/kid/pages/admin.php', ['tab' => 'promotions']);
    }
}
