<?php

use MintyPHP\Module\Audit\Service\UserLifecycleAuditService;
use MintyPHP\Module\Audit\Support\AuditPageHelper;
use MintyPHP\Router;
use MintyPHP\Service\Access\SettingsAuthorizationPolicy;
use MintyPHP\Support\Flash;

AuditPageHelper::requirePurgePost(
    SettingsAuthorizationPolicy::ABILITY_ADMIN_SETTINGS_UPDATE,
    'admin/settings/user-lifecycle',
    'user_lifecycle_audit'
);

$deleted = app(UserLifecycleAuditService::class)->purgeExpired();
Flash::success(
    sprintf(t('%d user lifecycle audit entries purged'), $deleted),
    'admin/settings/user-lifecycle',
    'user_lifecycle_audit_purged'
);
Router::redirect('admin/settings/user-lifecycle');
