<?php

namespace SugarCalendarBookings\Services\SmartTags;

use SugarCalendarBookings\Payments\PaymentsHelpers;
use SugarCalendarBookings\Services\ServiceModel;
use SugarCalendarBookings\Support\SmartTags\SmartTagInterface;

/**
 * Service Price smart tag.
 *
 * @since 1.0.0
 */
class ServicePriceSmartTag implements SmartTagInterface {

	/**
	 * Service model instance.
	 *
	 * @since 1.0.0
	 *
	 * @var ServiceModel
	 */
	private $service;

	/**
	 * Constructor.
	 *
	 * @since 1.0.0
	 *
	 * @param ServiceModel $service Service model instance.
	 */
	public function __construct( ServiceModel $service ) {

		$this->service = $service;
	}

	/**
	 * Get the smart tag key.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_key() {

		return '{service_price}';
	}

	/**
	 * Get the smart tag value.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_value() {

		if ( empty( $this->service->price ) ) {
			return '';
		}

		return html_entity_decode(
			PaymentsHelpers::format_currency( $this->service->price ),
			ENT_QUOTES,
			'UTF-8'
		);
	}
}
