<?php
namespace SabaiApps\Directories\Component\WooCommerce;

use SabaiApps\Directories\Component\Payment\IPlan;

class PaymentPlan implements IPlan {

	protected $_product;

	public function __construct( IProduct $product ) {
		$this->_product = $product;
	}

	public function getProduct() {
		return $this->_product;
	}

	public function paymentPlanId() {
		return $this->_product->get_id();
	}

	public function paymentPlanName() {
		return $this->_product->get_slug();
	}

	public function paymentPlanComponent() {
		return 'woocommerce';
	}

	public function paymentPlanType() {
		return $this->_product->get_sabai_plan_type();
	}

	public function paymentPlanTitle() {
		return $this->_product->get_name();
	}

	public function paymentPlanDescription() {
		return ( $desc = $this->_product->get_short_description() ) ? $desc : $this->_product->get_description();
	}

	public function paymentPlanFeatureList() {
		return array();
	}

	public function paymentPlanEntityLevel() {
		return (string) get_post_meta( $this->_getPostId(), '_drts_entity_level', true );
	}

	public function paymentPlanFeatures() {
		return (array) get_post_meta( $this->_getPostId(), '_drts_entity_features', true );
	}

	protected function _getPostId() {
		$post_id = $this->_product->get_id();
		if ( defined( 'WPML_PLUGIN_BASENAME' )
			&& ( $lang = apply_filters( 'wpml_default_language', null ) )
			&& ( $original_post_id = apply_filters( 'wpml_object_id', $post_id, 'product', false, $lang ) )
		) {
			$post_id = $original_post_id;
		}
		return $post_id;
	}

	public function paymentPlanIsFeatured() {
		return $this->_product->get_featured();
	}

	public function paymentPlanPrice() {
		return $this->_product->get_price();
	}

	public function paymentPlanIsPurchasable() {
		return $this->_product->is_purchasable()
			&& 'publish' === $this->_product->get_status();
	}

	public function paymentPlanInterval() {
		// TODO: Implement paymentPlanInterval() method.
	}

	public function paymentPlanIntervalCount() {
		// TODO: Implement paymentPlanIntervalCount() method.
	}
}
