<?php
/**
 * Migration class for the 'event_registrations' table.
 *
 * @package RadiusTheme\RadiusBooking
 * @since   1.2.0
 */

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;
}

/**
 * Class EventRegistrationsTable
 */
class EventRegistrationsTable extends Migration {

	/**
	 * Creates the 'event_registrations' table.
	 *
	 * @return void
	 */
	public function up(): void {
		Schema::create(
			$this->tablePrefix . 'event_registrations',
			function ( Blueprint $table ) {
				$table->id();
				$table->unsignedBigInteger( 'event_id' );
				$table->unsignedBigInteger( 'ticket_type_id' );
				$table->unsignedBigInteger( 'appointment_id' )->nullable();
				$table->unsignedBigInteger( 'customer_id' );
				$table->string( 'registration_number' )->nullable();
				$table->unsignedInteger( 'quantity' )->default( 1 );
				$table->json( 'attendee_info' )->nullable()->default( null );
				$table->string( 'status', 50 )->default( 'pending' );
				$table->unsignedInteger( 'waitlist_position' )->nullable();
				$table->string( 'check_in_token' )->nullable();
				$table->dateTime( 'checked_in_at' )->nullable();
				$table->timestamps();

				$table->index( 'event_id' );
				$table->index( 'ticket_type_id' );
				$table->index( 'appointment_id' );
				$table->index( 'customer_id' );
				$table->index( 'status' );
				$table->index( 'registration_number' );
			}
		);
	}

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