<?php

use App\Models\JobInfoType;
use App\Models\Job;
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('job_infos', function (Blueprint $table) {
            $table->id();

            $table->string('key')->unique();

            $table->string('name');
            $table->text('description')->nullable();
            $table->string('placeholder')->nullable();

            $table->text('value')->nullable();

            $table->boolean('is_required')->default(true);

            $table->foreignIdFor(JobInfoType::class, "job_info_type_id")->constrained()->onDelete('cascade');

            $table->foreignIdFor(Job::class,'job_id')->constrained()->onDelete('cascade');

            $table->timestamps();
        });

        $this->seed();
    }

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

    public function seed(): void
    {

        $jobInfos = [
            /* GENERAL PARAMETERS */
            [
                "key" => "discord_webhook_url",
                "name" => "Messages - Webhook Discord",
                "description" => "Le lien discord webhook utilisé pour envoyer les messages des résultats des jobs.",
                "placeholder" => "https://discord.com/api/webhooks/...",
                "job_info_type_id" => 4,
                "job_id" => 1,
            ],
            [
                "key" => "discord_error_webhook_url",
                "name" => "Alertes - Webhook Discord",
                "description" => "Le lien discord webhook utilisé pour envoyer les messages d'erreur et d'alerte. Laisser vide pour utiliser le même que les messages.",
                "placeholder" => "https://discord.com/api/webhooks/...",
                "is_required" => false,
                "job_info_type_id" => 4,
                "job_id" => 1,
            ],

            // /* EPIC GAMES */
            // [
            //     "key" => "epicgames_account_email",
            //     "name" => "E-mail",
            //     "description" => "L'adresse e-mail utilisée pour votre compte Epic Games.",
            //     "job_info_type_id" => 2,
            //     "job_id" => 3,
            // ],
            // [
            //     "key" => "epicgames_account_password",
            //     "name" => "Mot de passe",
            //     "description" => "Le mot de passe utilisé pour votre compte Epic Games.",
            //     "job_info_type_id" => 3,
            //     "job_id" => 3,
            // ],

            // /* INSTAGRAM */
            // [
            //     "key" => "instagram_account_email",
            //     "name" => "E-mail",
            //     "description" => "L'adresse e-mail utilisée pour votre compte Instagram.",
            //     "job_info_type_id" => 2,
            //     "job_id" => 4,
            // ],
            // [
            //     "key" => "instagram_account_password",
            //     "name" => "Mot de passe",
            //     "description" => "Le mot de passe utilisé pour votre compte Instagram.",
            //     "job_info_type_id" => 3,
            //     "job_id" => 4,
            // ],
        ];

        foreach ($jobInfos as $jobInfo) {
            \App\Models\JobInfo::forceCreate($jobInfo);
        }
    }
};
