<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('b2b_company_invitations', function (Blueprint $table) {
            $table->id();
            $table->integer('company_id')->unsigned();
            $table->string('email');
            $table->integer('company_role_id')->unsigned()->nullable();
            $table->integer('invited_by')->unsigned()->nullable();
            $table->string('token', 64)->unique();
            $table->string('status')->default('pending');
            $table->timestamp('expires_at')->nullable();
            $table->timestamps();

            $table->foreign('company_id')->references('id')->on('customers')->onDelete('cascade');
            $table->foreign('company_role_id')->references('id')->on('b2b_company_roles')->onDelete('set null');
        });
    }

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