<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     * Creates optimized Users table merging users + profiles + roles
     */
    public function up()
    {
        Schema::create('users_optimized', function (Blueprint $table) {
            $table->id();
            
            // Basic authentication
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            
            // Account type and simplified roles
            $table->enum('account_type', ['job_seeker', 'company_owner', 'admin'])->default('job_seeker');
            $table->enum('role', ['user', 'admin', 'moderator'])->default('user');
            $table->string('status')->default('active'); // active, suspended, banned
            
            // Profile information (merged from user_profiles + education_levels)
            $table->string('phone', 20)->nullable();
            $table->string('location')->nullable();
            $table->text('bio')->nullable();
            $table->string('avatar')->nullable();
            $table->date('date_of_birth')->nullable();
            $table->enum('gender', ['male', 'female', 'other', 'prefer_not_to_say'])->nullable();
            
            // Professional information
            $table->string('current_position')->nullable();
            $table->integer('years_experience')->nullable();
            $table->string('industry')->nullable();
            $table->string('highest_education_level')->nullable(); // instead of separate education_levels table
            $table->json('education_details')->nullable(); // detailed education info
            
            // Flexible profile data (JSON instead of multiple columns)
            $table->json('profile_data')->nullable(); // interests, social_links, achievements, etc.
            
            // Settings and preferences
            $table->json('email_notifications')->nullable(); // notification preferences
            $table->json('privacy_settings')->nullable(); // privacy configuration
            $table->json('preferences')->nullable(); // other user preferences
            
            // Timestamps
            $table->timestamps();
            
            // Indexes for performance
            $table->index(['account_type', 'status']);
            $table->index(['location', 'industry']);
            $table->index('email');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down()
    {
        Schema::dropIfExists('users_optimized');
    }
};