<?php

/**
 * Main CLI command of the plugin
 *
 * @link       https://wedima.de
 * @since      1.0.1
 *
 * @package    Wedima_Site
 * @subpackage Wedima_Site/cli/commands
 */

class Wedima_Site_Command
{
	/**
	 * Changes the maintenance mode of the plugin to the given mode.
	 *
	 * @param [type] $args
	 * @return void
	 */
	public function maintenance_mode($args)
	{
		$int_value = ctype_digit($args[0]) ? intval($args[0]) : null;
		if ($int_value === null || $int_value > 2 || $int_value < 0) {
			WP_CLI::warning('Usage: wp wedima-site mm [mode]');
			WP_CLI::line('modes: 0 - none, 1 - coming soon, 2 - maintenance');
		} else {
			update_option('wedima_site_maintenance_mode', $int_value);
			switch($int_value) {
				case 0:
					WP_CLI::success('site is public, no maintenance or coming soon mode active');
					break;
				case 1:
					WP_CLI::success('site is in coming soon mode');
					break;
				case 2:
					WP_CLI::success('site is in maintenance mode');
					break;
				default:
					WP_CLI::warning('site is in unknown mode');
					break;
			}
		}
	}

	/**
	 * Alias mm for maintenance_mode
	 *
	 * @param [type] $args
	 * @return void
	 */
	public function mm($args) {
		self::maintenance_mode($args);
	}
}
