<?php
/**
 * Handles the migration for creating and dropping the users table.
 *
 * The `up` method creates the `app_users` table with a prefixed table name, including columns
 * for user ID, name, email, phone, email verification timestamp, and timestamps for created
 * and updated records.
 *
 * The `down` method drops the `app_users` table.
 */

namespace RadiusTheme\RadiusBooking\Databases\Table;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}
use RadiusTheme\RadiusBooking\Core\Database\Schema\Blueprint;
use RadiusTheme\RadiusBooking\Abstracts\Migration;
use RadiusTheme\RadiusBooking\Core\Database\Schema\Schema;


/**
 * Handles the migration for creating and dropping the users table.
 *
 * The `up` method creates the users table with various columns such as id, name, email, phone,
 * email verification timestamp, and timestamps for created and updated records.
 *
 * The `down` method drops the users table.
 */
class UsersTable extends Migration {
	/**
	 * Creates the 'app_users' table in the database with prefixed table name defined by $tablePrefix.
	 * The table includes columns for user ID, name, unique email, optional phone, email verification timestamp, and timestamps for created and updated records.
	 *
	 * @return void
	 */
	public function up(): void {
		Schema::create(
			$this->tablePrefix . 'users',
			function ( Blueprint $table ) {
				$table->id();
				$table->string( 'user_type' );
				$table->string( 'email' )->unique();
				$table->string( 'password' )->nullable();
				$table->string( 'status' )->default( 'active' );
				$table->string( 'token' );
				$table->unsignedBigInteger( 'created_by' )->nullable();
				$table->timestamps();
			}
		);
	}

	/**
	 * Drops the app_users table prefixed by the defined table prefix.
	 *
	 * @return void
	 */
	public function down(): void {
		Schema::drop( $this->tablePrefix . 'users' );
	}
}
