<?php

namespace RadiusTheme\RadiusBooking\Models;

use RadiusTheme\RadiusBooking\Abstracts\BaseModel;
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}
/**
 * Class Location
 *
 * @package RadiusTheme\RadiusBooking\Models
 *
 * @property int    $id
 * @property string $name
 */
class Location extends BaseModel {

	/**
	 * The database table associated with the model.
	 *
	 * @var string
	 */
	protected string $table = 'radius_booking_locations';

	/**
	 * The attributes that are mass assignable.
	 *
	 * @var array
	 */
	protected array $fillable = array(
		'name',
		'description',
		'address',
		'latitude',
		'longitude',
		'phone',
		'image_id',
		'status',
		'translations',
	);

	/**
	 * The validation rules.
	 *
	 * @var array
	 */
	protected array $rules = array(
		'name' => 'required|string|max:255',
	);

	/**
	 * Retrieves the URL of the image associated with the given image ID.
	 *
	 * @return string Returns the full URL of the image if an image ID exists, or an empty string if no image ID is set.
	 */
	public function getImageUrl(): string {
		$image_id = $this->attributes['image_id'];
		if ( ! $image_id ) {
			return '';
		}
		return wp_get_attachment_image_url( $image_id, 'full' );
	}

	/**
	 * Retrieves the image ID associated with the given attributes.
	 *
	 * @return int|null Returns the image ID if it exists, or null if no image ID is set.
	 */
	public function getImageId() {
		return $this->attributes['image_id'] ?? null;
	}
}
