<?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('data', function (Blueprint $table) {
            $table->id();

            // Solo 1 data por entorno (unique)
            $table->foreignId('environment_id')
                ->unique()
                ->constrained('environments')
                ->cascadeOnDelete()
                ->cascadeOnUpdate();

            $table->boolean('policyagreed')->default(false);
            $table->string('language')->nullable();
            $table->string('countrycode')->nullable();
            $table->string('privacy')->nullable();
            $table->string('contactemail')->nullable();
            $table->integer('contactable')->default(0);
            $table->boolean('emailalert')->default(false);
            $table->string('emailalertemail')->nullable();
            $table->boolean('commnews')->default(false);
            $table->string('commnewsemail')->nullable();
            $table->string('contactname')->nullable();
            $table->string('description')->nullable();
            $table->string('imageurl')->nullable();
            $table->string('contactphone')->nullable();
            $table->string('regioncode')->nullable();
            $table->string('geolocation')->nullable();
            $table->string('street')->nullable();

            $table->integer('courses')->nullable();
            $table->integer('users')->nullable();
            $table->integer('activeusers')->nullable();
            $table->integer('enrolments')->nullable();
            $table->integer('posts')->nullable();
            $table->integer('questions')->nullable();
            $table->integer('resources')->nullable();
            $table->integer('badges')->nullable();
            $table->integer('issuedbadges')->nullable();

            $table->decimal('participantnumberaverage', 20, 2)->nullable();
            $table->decimal('activeparticipantnumberaverage', 20, 2)->nullable();
            $table->decimal('modulenumberaverage', 20, 2)->nullable();

            $table->string('moodlerelease')->nullable();
            $table->string('url')->nullable();
            $table->boolean('mobileservicesenabled')->default(false);
            $table->boolean('mobilenotificationsenabled')->default(false);

            $table->integer('registereduserdevices')->nullable();
            $table->integer('registeredactiveuserdevices')->nullable();
            $table->integer('analyticsenabledmodels')->nullable();
            $table->integer('analyticspredictions')->nullable();
            $table->integer('analyticsactions')->nullable();
            $table->integer('analyticsactionsnotuseful')->nullable();

            $table->string('availableupdatesfetch')->nullable();

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

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