<?php
/**
 * Uninstall cleanup for WrenchPress.
 *
 * Runs only on a genuine plugin delete. Removes the 3 custom roles, strips every
 * wrenchpress_* capability from the administrator role (ROLE-03), and deletes the
 * schema version option.
 *
 * The custom wp_wrenchpress_* tables are intentionally NOT dropped: the shop's
 * customer, vehicle, and service history is its asset and is preserved across an
 * uninstall. A future "delete all data on uninstall" setting could gate an
 * opt-in removal; until then the tables are left fully intact.
 *
 * @package WrenchPress
 */

defined( 'WP_UNINSTALL_PLUGIN' ) || exit;

require_once plugin_dir_path( __FILE__ ) . 'includes/class-capabilities.php';

$wrenchpress_roles = array(
	WrenchPress_Capabilities::ROLE_OWNER,
	WrenchPress_Capabilities::ROLE_FRONT_DESK,
	WrenchPress_Capabilities::ROLE_MECHANIC,
);

foreach ( $wrenchpress_roles as $wrenchpress_role ) {
	remove_role( $wrenchpress_role );
}

$wrenchpress_admin = get_role( 'administrator' );

if ( $wrenchpress_admin instanceof WP_Role ) {
	foreach ( WrenchPress_Capabilities::all_capabilities() as $wrenchpress_cap ) {
		$wrenchpress_admin->remove_cap( $wrenchpress_cap );
	}
}

// The option key matches WRENCHPRESS_DB_VERSION_OPTION in the main plugin file,
// which is not loaded during uninstall, so the literal string is used here.
delete_option( 'wrenchpress_db_version' );
