<?php
/**
 * Class Noesia Cs Product Repository.
 *
 * @package Noesia_Commerce_Suite
 */

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

/**
 * Class implementation.
 */
class Noesia_CS_Product_Repository {
	/**
	 * Handles the related plugin operation.
	 */
	public function is_available() {
		return class_exists( 'WooCommerce' ) && function_exists( 'wc_get_products' );
	}

	/**
	 * Handles the related plugin operation.
	 *
	 * @param mixed $limit Limit.
	 */
	public function get_published_products( $limit = 250 ) {
		if ( ! $this->is_available() ) {
			return array();
		}

		return wc_get_products(
			array(
				'limit'   => max( 1, min( 1000, absint( $limit ) ) ),
				'status'  => array( 'publish' ),
				'return'  => 'objects',
			)
		);
	}
}
