<?php
/**
 * Migration class for the 'user_profiles' 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;

/**
 * Class UserProfilesTable
 *
 * @package RadiusTheme\RadiusBooking\Databases\Table
 * Migration for creating the 'user_profiles' table.
 */
class UserProfilesTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up(): void {
		Schema::create(
			$this->tablePrefix . 'user_profiles',
			function ( Blueprint $table ) {
				$table->id();
				$table->unsignedBigInteger( 'user_id' );
				$table->foreign( 'user_id' )->references( 'id' )->on( $this->tablePrefix . 'users' )->name( 'fk_user_profiles_user_id' )->cascadeOnDelete();
				$table->integer( 'wp_user_id' )->nullable();
				$table->bigInteger( 'listing_id' )->nullable();
				$table->string( 'source_type' )->default( 'manual' );
				$table->string( 'first_name' )->nullable();
				$table->string( 'last_name' )->nullable();
				$table->string( 'phone' )->nullable();
				$table->bigInteger( 'image_id' )->nullable();
				$table->string( 'gender' );
				$table->string( 'time_zone' )->nullable();
				$table->longText( 'note' )->nullable();
				$table->integer( 'badge_id' )->nullable();
				$table->integer( 'location_id' )->nullable();
				$table->json( 'translations' )->nullable()->default( null );
				$table->timestamps();
			}
		);
	}

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