<?php
/**
 * Repository class for managing AppointmentIntegration data.
 *
 * @package RadiusTheme\RadiusBooking\Repositories
 */

namespace RadiusTheme\RadiusBooking\Repositories;

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

/**
 * Class AppointmentIntegrationRepository
 *
 * Handles data operations for the AppointmentIntegration model.
 */
class AppointmentIntegrationRepository extends BaseRepository {

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

	/**
	 * Find an AppointmentIntegration by appointment ID and provider.
	 *
	 * @param int|string $appointmentId Appointment ID.
	 * @param string     $provider      Provider identifier.
	 *
	 * @return mixed|object|null
	 */
	public function findByAppointmentAndProvider( $appointmentId, $provider ) {
		return AppointmentIntegration::where( 'appointment_id', $appointmentId )
							->where( 'provider', $provider )
							->first();
	}

	/**
	 * Get all AppointmentIntegrations by appointment ID.
	 *
	 * @param int|string $appointmentId Appointment ID.
	 *
	 * @return \Illuminate\Database\Eloquent\Collection|static[]
	 */
	public function getByAppointment( $appointmentId ) {
		return AppointmentIntegration::where( 'appointment_id', $appointmentId )->get();
	}

	/**
	 * Delete AppointmentIntegrations by appointment ID.
	 *
	 * @param int|string $appointmentId Appointment ID.
	 *
	 * @return int
	 */
	public function deleteByAppointment( $appointmentId ) {
		return AppointmentIntegration::where( 'appointment_id', $appointmentId )->delete();
	}
}
