<?php

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

class CreatePcDeviceModelsTable extends Migration
{
    public function up()
    {
        if (Schema::hasTable('pc_device_models')) {
            return;
        }

        Schema::create('pc_device_models', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedInteger('business_id');

            $table->string('brand')->nullable();
            $table->string('series')->nullable();
            $table->string('model');
            // brand|series|model normalized for de-dup.
            $table->string('normalized_key');

            $table->timestamps();

            $table->index(['business_id', 'brand']);
            $table->unique(['business_id', 'normalized_key'], 'pc_device_models_unique');
        });
    }

    public function down()
    {
        Schema::dropIfExists('pc_device_models');
    }
}
