<?php

namespace SugarCalendarBookings\Locations;

/**
 * In-person location.
 *
 * @since 1.0.0
 */
class InPersonLocation extends AbstractLocation {

	/**
	 * The location model.
	 *
	 * @since 1.0.0
	 *
	 * @var LocationModel
	 */
	private $model;

	/**
	 * Constructor.
	 *
	 * @since 1.0.0
	 *
	 * @param LocationModel $model The location model.
	 */
	public function __construct( $model ) {

		$this->model = $model;
	}

	/**
	 * Get the location type.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_type() {

		return 'in_person';
	}

	/**
	 * Get the location ID.
	 *
	 * @since 1.0.0
	 *
	 * @return int
	 */
	public function get_id() {

		return $this->model->id;
	}

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

		return $this->model->name;
	}

	/**
	 * Get the location address.
	 *
	 * @since 1.0.0
	 *
	 * @return null|string
	 */
	public function get_address() {

		return LocationsHelpers::format_address( $this->model );
	}

	/**
	 * Get the location model.
	 *
	 * @since 1.0.0
	 *
	 * @return LocationModel
	 */
	public function get_model() {

		return $this->model;
	}

	/**
	 * Get a location by ID.
	 *
	 * @since 1.0.0
	 *
	 * @param int $id The location ID.
	 *
	 * @return AbstractLocation|null
	 */
	public static function get( $id ) {

		$model = LocationModel::get( $id );

		if ( ! $model ) {
			return null;
		}

		return new InPersonLocation( $model );
	}
}
