<?php

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

class CreateContactsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('contacts', function (Blueprint $table) {
            $table->id();
            $table->string('ms_contact_id');
            $table->unsignedBigInteger('contact_folder_id');
            $table->string('display_name');
            $table->string('email');
            $table->string('given_name')->nullable();
            $table->string('surname')->nullable();
            $table->timestamps();

            // Foreign keys
            $table->foreign('contact_folder_id')
                ->references('id')
                ->on('contact_folders')
                ->onDelete('cascade')
                ->onUpdate('cascade');

            // indexes
            $table->index('contact_folder_id');
            $table->index('email');
        });
    }

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