<?php

/**
 * @file
 * Install, update and uninstall functions for the Sobki Assets module.
 */

declare(strict_types=1);

use Drupal\Core\File\FileSystemInterface;
use Drupal\sobki_assets\Form\AssetsUploadForm;

/**
 * Implements hook_install().
 */
function sobki_assets_install(): void {
  $fileSystem = \Drupal::service('file_system');
  $options = FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS;
  $directory = AssetsUploadForm::DESTINATION_DIRECTORY;
  $fileSystem->prepareDirectory($directory, $options);
}

/**
 * Implements hook_uninstall().
 */
function sobki_assets_uninstall(): void {
  $purger = \Drupal::service('sobki_assets.destination_directory_purger');
  $purger->purge();
  $purger->removeDestinationDirectory();
}
