<?php

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

/**
 * The people who run CluPilot: the owner and the staff.
 *
 * Their own table rather than a flag on `users`, because a flag lets the state
 * "operator who is also a portal account" reappear at any time — and that state
 * is why OperatorInPortalTest had to exist: an operator without a customer
 * could wander into the portal and press buttons that did nothing. A separate
 * table makes the class of fault impossible rather than caught.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('operators', function (Blueprint $table) {
            $table->id();
            $table->uuid()->unique();

            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();

            // Same column names Fortify's TwoFactorAuthenticatable expects.
            $table->text('two_factor_secret')->nullable();
            $table->text('two_factor_recovery_codes')->nullable();
            $table->timestamp('two_factor_confirmed_at')->nullable();

            // Who is still active — the basis for the staff view that comes later.
            $table->timestamp('last_login_at')->nullable();

            // A member of staff who has left, without deleting the audit trail
            // their id appears in.
            $table->timestamp('disabled_at')->nullable();

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

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