<?php
namespace OxygenApp;

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

use OxygenApp\Hooks\HooksFactory;
use OxygenApp\Models\SchemaManager;
use OxygenApp\Models\BackgroundSound;
use OxygenApp\Models\Background;
use OxygenApp\Models\AdminPlaylist;
use OxygenApp\Models\BackgroundCategory;
use OxygenApp\Utils\OptionUtils;

class App {
    static function run(mixed $file): void {
        HooksFactory::registerHooks();
        register_activation_hook(
            $file,
            [self::class, 'onActivate']
        );
        
        register_uninstall_hook(
            $file,
            [self::class, 'onUninstall']
        );
    }

    static function onActivate(): void {
        SchemaManager::createUsersTable();
    }

    static function onUninstall(): void {
        $clean_up_on_uninstall = OptionUtils::getInstance()->getOption('clean_up_on_uninstall');
        if ($clean_up_on_uninstall !== 'on') {
            return;
        }

        BackgroundSound::cleanupOnUninstall();
        Background::cleanupOnUninstall();

        AdminPlaylist::cleanupOnUninstall();
        BackgroundCategory::cleanupOnUninstall();

        SchemaManager::deleteUsersTable();

        SchemaManager::cleanupPluginOptions();
        
        flush_rewrite_rules();
    }
}