<?php
/**
 * Bulk queue management for STWP plugin.
 *
 * @package STWP
 * @since 1.1.0
 */

namespace STWP;

// If this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
	die( 'Direct access not allowed.' );
}

/**
 * Bulk_Queue class manages bulk conversion queue.
 *
 * @since 1.0.0
 */
class Bulk_Queue {

	/**
	 * Build conversion queue from existing attachments.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public static function build_queue() {
		$args = array(
			'post_type'      => 'attachment',
			'post_mime_type' => array( 'image/jpeg', 'image/png', 'image/gif', 'image/heic', 'image/heif' ),
			'posts_per_page' => -1,
			'fields'         => 'ids',
		);

		$ids = \get_posts( $args );

		\update_option( 'stwp_bulk_queue', $ids, false );
		\update_option( 'stwp_bulk_done', array(), false );
		\update_option( 'stwp_bulk_errors', array(), false );
		\update_option( 'stwp_bulk_running', true, false );
	}
}
