<?php
/**
 * JJ\'s Post Scheduler capabilities.
 *
 * @package ScheduledChanges
 */

namespace ScheduledChanges\Capabilities;

/**
 * Adds and removes role capabilities using conservative defaults.
 */
final class CapabilityManager {
	public const VIEW_SCHEDULES     = 'scheduled_changes_view_schedules';
	public const EDIT_SCHEDULES     = 'scheduled_changes_edit_schedules';
	public const CREATE_SCHEDULES   = 'scheduled_changes_create_schedules';
	public const DELETE_SCHEDULES   = 'scheduled_changes_delete_schedules';
	public const SCHEDULE_CHANGES   = 'scheduled_changes_schedule_changes';
	public const EXECUTE_SCHEDULES  = 'scheduled_changes_execute_schedules';
	public const ROLLBACK_SCHEDULES = 'scheduled_changes_rollback_schedules';
	public const VIEW_LOGS          = 'scheduled_changes_view_logs';
	public const MANAGE_SETTINGS    = 'scheduled_changes_manage_settings';

	/**
	 * All plugin capabilities.
	 *
	 * @return list<string>
	 */
	public static function all(): array {
		return array(
			self::VIEW_SCHEDULES,
			self::EDIT_SCHEDULES,
			self::CREATE_SCHEDULES,
			self::DELETE_SCHEDULES,
			self::SCHEDULE_CHANGES,
			self::EXECUTE_SCHEDULES,
			self::ROLLBACK_SCHEDULES,
			self::VIEW_LOGS,
			self::MANAGE_SETTINGS,
		);
	}

	/**
	 * Grants default capabilities.
	 */
	public function install(): void {
		$administrator = get_role( 'administrator' );

		if ( $administrator ) {
			foreach ( self::all() as $capability ) {
				$administrator->add_cap( $capability );
			}
		}
	}
}
