<?php

/**
 * Block Builder data cleanup when LolaCore is uninstalled.
 *
 * @package LolaCore\BlockBuilder
 * @license GPL-2.0-or-later
 */

declare(strict_types=1);

namespace LolaCore\BlockBuilder;

use LolaCore\BlockBuilder\PostType\BlockPostType;

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

/**
 * Removes built-block library entries (CPT posts, meta, and revisions).
 *
 * Does NOT delete block folders under wp-content/lolacore-blocks/ (use uninstall_block for that).
 */
class BlockBuilderUninstall {

	public static function deleteLibrary(): void {
		$posts = get_posts(
			array(
				'post_type'      => BlockPostType::POST_TYPE,
				'post_status'    => 'any',
				'posts_per_page' => -1,
				'fields'         => 'ids',
			)
		);

		if (! is_array($posts)) {
			return;
		}

		foreach ($posts as $post_id) {
			wp_delete_post((int) $post_id, true);
		}
	}
}
