<?php
/**
 * Migration class for the 'event_sessions' 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 EventSessionsTable
 */
class EventSessionsTable extends Migration {

	/**
	 * Creates the 'event_sessions' table.
	 *
	 * @return void
	 */
	public function up(): void {
		Schema::create(
			$this->tablePrefix . 'event_sessions',
			function ( Blueprint $table ) {
				$table->id();
				$table->unsignedBigInteger( 'event_id' );
				$table->string( 'name' );
				$table->text( 'description' )->nullable();
				$table->date( 'session_date' );
				$table->time( 'start_time' );
				$table->time( 'end_time' );
				$table->string( 'speaker' )->nullable();
				$table->unsignedInteger( 'capacity' )->nullable();
				$table->string( 'location_override' )->nullable();
				$table->unsignedInteger( 'sort_order' )->default( 0 );
				$table->timestamps();

				$table->index( 'event_id' );
				$table->index( 'session_date' );
			}
		);
	}

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