<?php
namespace RadiusTheme\RadiusBooking\Repositories;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}
use RadiusTheme\RadiusBooking\Abstracts\BaseRepository;
use RadiusTheme\RadiusBooking\Models\Location;

/**
 * Class LocationRepository
 *
 * Handles data operations for the Location model.
 */
class LocationRepository extends BaseRepository {

	/**
	 * The model class managed by this repository.
	 *
	 * @var string
	 */
	protected string $model = Location::class;

	/**
	 * Fetches location data based on the given location ID.
	 *
	 * @param int $locationId The ID of the location to retrieve data for.
	 *
	 * @return array An associative array containing the location's ID, name, address, and phone number.
	 */
	public function getLocationData( int $locationId ): array {
		if( ! $locationId) return array();
		$location = Location::find( $locationId );
		return array(
			'id'      => $location->id,
			'name'    => $location->name,
			'address' => $location->address,
			'phone'   => $location->phone,
		);
	}

	/**
	 * Retrieves the image URL for a given location.
	 *
	 * @param int $locationId The ID of the location.
	 *
	 * @return string The URL of the image if available; otherwise, an empty string.
	 */
	public function getImageUrl( $locationId ) {
		$location = Location::find( $locationId );
		if ( ! $location || ! $location->image_id ) {
			return '';
		}
		return $location->getImageUrl();
	}
}
