<?php

namespace SugarCalendarBookings\Locations;

/**
 * Online location Zoom provider.
 *
 * Stores just the provider type at service creation time.
 * The actual meeting URL is generated when an appointment is booked.
 *
 * @since 1.4.0
 */
class ZoomProvider extends AbstractOnlineLocationProvider {

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

		return esc_html__( 'Zoom Meeting', 'sugar-calendar-bookings-scheduling-appointments-lite' );
	}

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

		return new ZoomProvider();
	}

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

		return [
			'provider' => 'zoom',
		];
	}

	/**
	 * Get the Zoom meeting join URL from appointment data.
	 *
	 * @since 1.4.0
	 *
	 * @param array $online_location_data The appointment's online_location meta data.
	 *
	 * @return string The join URL, or empty string if unavailable.
	 */
	public function get_appointment_url( $online_location_data ) {

		return $online_location_data['join_url'] ?? '';
	}
}
