<?php

use App\Models\Achievement;
use App\Models\AchievementCategory;
use App\Models\AchievementDifficulty;
use App\Models\Aircraft;
use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use function React\Promise\all;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Aircraft::create([
            'designator' => 'B731',
            'manufacturer_code' => 'BOEING',
            'model_full_name' => '737-100',
            'aircraft_description' => 'LandPlane',
            'engine_type' => 'Jet',
            'engine_count' => 2,
            'wtc' => 'M',
            'preferred' => false,
        ]);

        $modelNames = ['737-8', '737-9', '737-10', '737-7'];
        Aircraft::whereIn('model_full_name', $modelNames)->delete();

        $impossible = AchievementDifficulty::where('internal_name', 'impossible')->first();
        $aircraftCategory = AchievementCategory::where('internal_name', 'aircraft')->first();

        Achievement::create([
            'internal_name' => 'aircraft.all_boeing_737',
            'name' => 'Rarest of the Commoners',
            'short_description' => 'Fly Every Variant of the Boeing 737',
            'icon' => 'standard_achievement.png',
            'achievement_category_id' => $aircraftCategory->id,
            'achievement_difficulty_id' => $impossible->id,
            'progressive' => true,
            'threshold' => 13,
            'sort_order' => 7,
            'has_page' => true,
            'long_description' => ''
        ]);

        foreach(User::all() as $user){
            $user->calculateAchievements();
        }

    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        //
    }
};
