<?php

namespace WooPoPCozmosLabsPMS\Providers;

use WcElectronInvoice\Providers\ProductsProviderAbstract;
use WcElectronInvoice\Providers\ProductsQuery;

defined( 'ABSPATH' ) || die( 'Not allowed.' );

class ProductsProvider extends ProductsProviderAbstract {

	/**
	 * @inheritDoc
	 */
	function getProducts( $args = array() ) {

		$args = $this->mapArgs( $args );

		$subscriptions = pms_get_member_subscriptions( $args );

		foreach ($subscriptions as $index => $subscription) {
			$subscriptions[ $index ] = new Product( $subscription );
		}

		return $subscriptions;

	}

	/**
	 * @inheritDoc
	 */
	function getProduct( $product_id ) {

		$subscription = pms_get_subscription_plan( $product_id );

		return new Product( $subscription );

	}

	/**
	 * @inheritDoc
	 */
	function enqueue() {
		ProductsQuery::instance()->register_provider( $this );
	}

	/**
	 * @inheritDoc
	 */
	function name() {
		return 'cozmoslabspms';
	}

	/**
	 * @inheritDoc
	 */
	private function mapArgs( $args ) {
		// TODO: map WC args for PMS
		return $args;
	}
}
