<?php

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

/**
 * Pet-owner login accounts for the public portal. Each links to an ERP
 * contact (the pet owner). Authenticated via the dedicated `pet_owner` guard.
 */
class CreateVpPortalAccountsTable extends Migration
{
    public function up()
    {
        if (Schema::hasTable('vp_portal_accounts')) return;

        Schema::create('vp_portal_accounts', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('business_id')->index();
            $table->unsignedInteger('contact_id')->index();
            $table->string('name', 150);
            $table->string('email', 150)->unique();
            $table->string('password', 255);
            $table->boolean('enabled')->default(true);
            $table->dateTime('last_login_at')->nullable();
            $table->rememberToken();
            $table->timestamps();
        });
    }

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