<?php
/**
 * Activation handler.
 *
 * @package TradeSchoolManager
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class TSM_Activator {
	public static function activate() {
		require_once TSM_PLUGIN_DIR . 'includes/class-tsm-db.php';
		require_once TSM_PLUGIN_DIR . 'includes/class-tsm-roles.php';
		TSM_DB::install();
		TSM_Roles::add_roles();

		// Default settings.
		if ( ! get_option( 'tsm_settings' ) ) {
			add_option(
				'tsm_settings',
				array(
					'school_name'   => get_bloginfo( 'name' ),
					'school_logo'   => '',
					'brand_color'   => '#1f6feb',
					'grading_scale' => "A: 90\nB: 80\nC: 70\nD: 60\nF: 0",
					'terminology'   => array(
						'class'   => 'Class',
						'student' => 'Student',
						'teacher' => 'Teacher',
					),
				)
			);
		}

		// First-run flag  -  drives the dismissible "Setup Walkthrough is over
		// here" admin notice on the next page load. Only set on fresh install
		// (not on reactivation of an existing install with data).
		if ( ! get_option( 'tsm_first_run_seen' ) ) {
			set_transient( 'tsm_show_welcome_notice', 1, WEEK_IN_SECONDS );
		}

		flush_rewrite_rules();
	}
}
