<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        // جدول عجلة الحظ
        Schema::create('entertainment_wheels', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->onDelete('cascade');
            $table->boolean('is_free')->default(true);
            $table->string('prize_type');
            $table->string('prize_emoji');
            $table->text('prize_description');
            $table->timestamp('spun_at');
            $table->timestamps();
        });

        // جدول التعدين
        Schema::create('entertainment_minings', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->onDelete('cascade');
            $table->integer('current_points')->default(0);
            $table->integer('daily_points')->default(0);
            $table->integer('mining_speed')->default(1);
            $table->timestamp('last_mining')->nullable();
            $table->timestamps();
        });

        // جدول حزم الجواهر
        Schema::create('entertainment_gems', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('name_ar');
            $table->integer('gems');
            $table->decimal('price', 10, 2);
            $table->text('description')->nullable();
            $table->text('description_ar')->nullable();
            $table->boolean('is_active')->default(true);
            $table->timestamps();
        });

        // جدول مشتريات الجواهر
        Schema::create('entertainment_purchases', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->onDelete('cascade');
            $table->integer('package_id');
            $table->integer('gems');
            $table->decimal('price', 10, 2);
            $table->timestamp('purchased_at');
            $table->timestamps();
        });

        // إضافة حقول جديدة لجدول المستخدمين
        Schema::table('users', function (Blueprint $table) {
            $table->integer('gems')->default(0)->after('status');
            $table->integer('free_rides')->default(0)->after('gems');
            $table->integer('free_meals')->default(0)->after('free_rides');
            $table->integer('discounts')->default(0)->after('free_meals');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('entertainment_purchases');
        Schema::dropIfExists('entertainment_gems');
        Schema::dropIfExists('entertainment_minings');
        Schema::dropIfExists('entertainment_wheels');

        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn(['gems', 'free_rides', 'free_meals', 'discounts']);
        });
    }
};
