<?php

use App\Models\Job;
use App\Models\JobInfo;
use App\Models\JobInfoType;
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
    {
        $newJobId = 3;
        Job::forceCreate([
            "id" => $newJobId,
            "name" => "Hellcase Battles",
            "description" => "Envoie les meilleures battles d'Hellcase",
        ]);

        JobInfo::forceCreate([
            "key" => "hellcase_battles_discord_webhook_url",
            "name" => "Webhook Discord",
            "description" => "Le lien discord webhook utilisé pour envoyer les meilleures battles d'Hellcase.\nSi aucun n'est spécifié, le webhook Discord des paramètres généraux sera utilisé.",
            "placeholder" => "https://discord.com/api/webhooks/...",
            "is_required" => false,
            "job_info_type_id" => 4,
            "job_id" => $newJobId,
        ]);

        JobInfoType::forceCreate([
            "id" => 5,
            "name" => "number",
        ]);
        JobInfoType::forceCreate([
            "id" => 6,
            "name" => "boolean",
        ]);

        JobInfo::forceCreate([
            "key" => "hellcase_battles_minimum_value",
            "name" => "Valeur minimum des battles",
            "description" => "La valeur minimale qu'une battle doit avoir pour être envoyée, en euros.",
            "placeholder" => "1000",
            "job_info_type_id" => 5,
            "job_id" => $newJobId,
        ]);

        JobInfo::forceCreate([
            "key" => "hellcase_battles_allow_bots",
            "name" => "Autoriser les battles avec bots",
            "description" => "Envoyer les battles avec un seul joueur et des bots.",
            "is_required" => false,
            "job_info_type_id" => 6,
            "job_id" => $newJobId,
        ]);

        Schema::create('hellcase_battles', function (Blueprint $table) {
            $table->id();

            $table->string("battle_id")->unique();
            $table->float("value");

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Job::where("id", 3)->delete();
        JobInfo::where("job_id", 3)->delete();
        JobInfoType::whereIn("id", [5, 6])->delete();

        Schema::dropIfExists('hellcase_battles');
    }
};
