<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('object_proto', function (Blueprint $table) {
            $table->unsignedInteger('vnum')->primary();
            $table->string('name', 32);
            $table->unsignedInteger('price');
            $table->string('materials', 64);
            $table->unsignedInteger('upgrade_vnum')->default(0);
            $table->unsignedInteger('upgrade_limit_time')->default(0);
            $table->integer('life')->default(0);
            $table->integer('reg_1')->default(0);
            $table->integer('reg_2')->default(0);
            $table->integer('reg_3')->default(0);
            $table->integer('reg_4')->default(0);
            $table->unsignedInteger('npc')->default(0);
            // TODO Check the items below as they might be indexeable
            $table->unsignedInteger('group_vnum')->default(0);
            $table->unsignedInteger('dependent_group')->default(0);
        });

        // Populate the table data
        $data = File::json(database_path('data/object_proto.json'));
        \App\Models\Game\Player\ObjectProto::upsert($data, ['vnum']);
    }

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