<?php

namespace SugarCalendarBookings\Locations;

/**
 * Online location custom link provider.
 *
 * @since 1.0.0
 */
class CustomLinkProvider extends AbstractOnlineLocationProvider {

	/**
	 * The meeting URL.
	 *
	 * @since 1.0.0
	 *
	 * @var string
	 */
	private $url;

	/**
	 * Constructor.
	 *
	 * @since 1.0.0
	 *
	 * @param string $url The meeting URL.
	 */
	public function __construct( $url ) {

		$this->url = $url;
	}

	/**
	 * Get the provider display name.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_display_name() {

		return $this->url;
	}

	/**
	 * Create a custom link provider from an array.
	 *
	 * @since 1.0.0
	 *
	 * @param array $data The location data.
	 *
	 * @return AbstractOnlineLocationProvider
	 */
	public static function from_array( $data ) {

		return new CustomLinkProvider( $data['url'] ?? '' );
	}

	/**
	 * Convert the provider to an array.
	 *
	 * @since 1.0.0
	 *
	 * @return array
	 */
	public function to_array() {

		return [
			'provider' => 'custom_link',
			'url'      => $this->url,
		];
	}

	/**
	 * Get the custom meeting link URL.
	 *
	 * @since 1.4.0
	 *
	 * @param array $online_location_data The appointment's online_location meta data.
	 *
	 * @return string The custom link URL.
	 */
	public function get_appointment_url( $online_location_data ) {

		return $this->url;
	}
}
