<?php

/**
 * Removes Parkstatic files and options on plugin deletion.
 *
 * @package Parkstatic
 */
declare (strict_types = 1);
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
/**
 * Cleans up all Parkstatic artifacts from the WordPress installation.
 */
final class Parkstatic_Uninstaller {
    /** @var string[] */
    private const OPTIONS = array(
        'parkstatic_instance_uuid',
        'parkstatic_started',
        'parkstatic_onboarding_complete',
        'parkstatic_repo_url',
        'parkstatic_onboarding_step',
        'parkstatic_token_version',
        'parkstatic_registered_token_hash',
        'parkstatic_token_refresh_pending',
        'parkstatic_deploy_token_hash',
        'parkstatic_deploy_secret',
        'parkstatic_last_deploy_at',
        'parkstatic_last_deploy_error',
        'parkstatic_registration_error',
        'parkstatic_static_mode_enabled',
        'parkstatic_meta_inject_enabled',
        'parkstatic_storage_migrated_v1',
        'parkstatic_htaccess_storage_version',
        'parkstatic_legacy_asset_base'
    );

    /** @var string[] */
    private const PREMIUM_OPTIONS = array(
        'parkstatic_og_title',
        'parkstatic_og_description',
        'parkstatic_og_image_id',
        'parkstatic_auto_release',
        'parkstatic_active_release'
    );

    /** @var string[] */
    private const TRANSIENTS = array('parkstatic_deploy_token_once', 'parkstatic_activation_redirect');

    public static function run() : void {
        self::remove_created_directories();
        self::delete_options();
        self::delete_transients();
        flush_rewrite_rules();
    }

    private static function remove_created_directories() : void {
        Parkstatic_Storage::remove_directory_tree( Parkstatic_Storage::base_dir() );
        Parkstatic_Storage::remove_directory_tree( Parkstatic_Storage::legacy_base_dir() );
    }

    private static function delete_options() : void {
        foreach ( self::OPTIONS as $option ) {
            delete_option( $option );
        }
    }

    private static function delete_transients() : void {
        foreach ( self::TRANSIENTS as $transient ) {
            delete_transient( $transient );
        }
    }

}
