<?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.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

namespace mod_booking\booking_rules\rules\templates;

use context;
use mod_booking\booking_rules\actions_info;
use mod_booking\booking_rules\conditions_info;
use mod_booking\singleton_service;
use MoodleQuickForm;
use stdClass;

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

require_once($CFG->dirroot . '/mod/booking/lib.php');

/**
 * Rule do something a specified number of days before a chosen date.
 *
 * @package mod_booking
 * @copyright 2022 Wunderbyte GmbH <info@wunderbyte.at>
 * @author Georg Maißer
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class ruletemplate_trainerpoll {
    /** @var int $templateid */
    public static $templateid = 8;

    /** @var int $eventtype */
    public static $eventtype = 'rule_daysbefore';

    /**
     * Returns the localized name of this template
     *
     * @return string
     *
     */
    public static function get_name() {
        return get_string('ruletemplatetrainerpoll', 'booking');
    }

    /**
     * Returns the template as if it came from DB.
     *
     * @return object
     *
     */
    public static function return_template() {

        $rulejson = (object)[
            "conditionname" => "select_teacher_in_bo",
            "conditiondata" => [],
            "name" => self::get_name(),
            "actionname" => "send_mail",
            "actiondata" => [
                "subject" => get_string('ruletemplatetrainerpollsubject', 'booking'),
                "template" => get_string('ruletemplatetrainerpollbody', 'booking'),
                "templateformat" => "1",
            ],
            "rulename" => "rule_daysbefore",
            "ruledata" => [
                "days" => "0",
                "datefield" => "courseendtime",
            ],
        ];

        $returnobject = [
            'id' => self::$templateid,
            'rulename' => self::$eventtype,
            'rulejson' => json_encode($rulejson),
            'eventname' => "\\mod_booking\\event\\bookingoption_completed",
            'contextid' => 1,
            'useastemplate' => 0,
        ];
        return (object) $returnobject;
    }
}
