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

	/**
	 * Creates the 'events' table.
	 *
	 * @return void
	 */
	public function up(): void {
		Schema::create(
			$this->tablePrefix . 'events',
			function ( Blueprint $table ) {
				$table->id();
				$table->unsignedBigInteger( 'organizer_id' );
				$table->string( 'name' );
				$table->string( 'slug' )->nullable();
				$table->text( 'description' )->nullable();
				$table->text( 'short_description' )->nullable();
				$table->string( 'event_type', 50 )->default( 'single' );
				$table->date( 'start_date' );
				$table->date( 'end_date' )->nullable();
				$table->time( 'start_time' );
				$table->time( 'end_time' );
				$table->string( 'timezone', 100 )->nullable();
				$table->string( 'location_type', 50 )->default( 'physical' );
				$table->text( 'location_value' )->nullable();
				$table->unsignedInteger( 'category_id' )->nullable();
				$table->unsignedInteger( 'capacity' )->nullable();
				$table->unsignedInteger( 'registered_count' )->default( 0 );
				$table->boolean( 'waitlist_enabled' )->default( 0 );
				$table->unsignedInteger( 'waitlist_capacity' )->nullable();
				$table->enum( 'status', array( 'draft', 'published', 'cancelled', 'completed' ) )->default( 'draft' );
				$table->dateTime( 'registration_deadline' )->nullable();
				$table->json( 'recurring_pattern' )->nullable()->default( null );
				$table->json( 'settings' )->nullable()->default( null );
				$table->string( 'picture_full_path' )->nullable();
				$table->string( 'picture_thumb_path' )->nullable();
				$table->boolean( 'is_featured' )->default( 0 );
				$table->timestamps();
				$table->softDeletes();

				$table->index( 'organizer_id' );
				$table->index( 'slug' );
				$table->index( 'status' );
				$table->index( 'category_id' );
				$table->index( 'start_date' );
				$table->index( 'is_featured' );
			}
		);
	}

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