<?php

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

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // Tabla de partners
        Schema::create('partners', function (Blueprint $table) {
            $table->id(); // partner id
            $table->string('name'); // partner name
            $table->timestamps();
        });

        // Tabla de partner_invites
        Schema::create('partner_invites', function (Blueprint $table) {
            $table->id(); // invite id
            $table->unsignedBigInteger('user_id'); // user id (relacionado con ampeco_user_id, no FK directa por flexibilidad)
            $table->unsignedBigInteger('partner_id'); // partner id (relacionado con partners.id)
            $table->string('status')->default('pending');
            $table->timestamps();

            // Índices para consultas eficientes
            $table->index('user_id');
            $table->index('partner_id');
            $table->index('status');

            // Foreign key solo para partner_id
            $table->foreign('partner_id')->references('id')->on('partners')->onDelete('cascade');
            // Si en el futuro user_id se relaciona con otra tabla, agregar FK aquí:
            // $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        });
    }

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