<?php
/**
 * Migration class for the 'appointment_integrations' table.
 */

namespace RadiusTheme\RadiusBooking\Databases\Table;

use RadiusTheme\RadiusBooking\Core\Database\Schema\Blueprint;
use RadiusTheme\RadiusBooking\Abstracts\Migration;
use RadiusTheme\RadiusBooking\Core\Database\Schema\Schema;
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}
/**
 * Class AppointmentIntegrationsTable
 *
 * @package RadiusTheme\RadiusBooking\Databases\Table
 * Migration for creating the 'appointment_integrations' table.
 */
class AppointmentIntegrationsTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up(): void {
		Schema::create(
			$this->tablePrefix . 'appointment_integrations',
			function ( Blueprint $table ) {
				$table->id();
				// Reference to appointment
				$table->unsignedBigInteger( 'appointment_id' )->index();
				// Integration provider name: google, zoom, teams, apple, etc.
				$table->string( 'provider', 50 );
				// External identifiers
				$table->string( 'external_event_id' )->nullable();
				$table->string( 'external_calendar_id' )->nullable();

				// Meeting / event data
				$table->string( 'meeting_url' )->nullable();
				$table->string( 'join_url' )->nullable(); // for Zoom/Teams
				$table->string( 'start_url' )->nullable(); // host link (Zoom)
				$table->json( 'meta' )->nullable(); // store raw API response or extra fields

				// Status tracking
				$table->string( 'status', 50 )->default( 'created' );
				$table->timestamps();
			}
		);
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down(): void {
		Schema::drop( $this->tablePrefix . 'appointment_integrations' );
	}
}
