<?php

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

class CreateUserDocumentsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_documents', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('company_id');
            $table->unsignedBigInteger('document_type_id');
            $table->string('support_document');
            $table->enum('status', ['0', '1','2'])->default('0'); //0: Pendiente, 1: Aprobado, 2: Rechazado
            $table->text('rejected_reason')->nullable();
            $table->unsignedBigInteger('reviewed_by')->nullable();
            $table->foreign('user_id')->references('id')->on('users')
                    ->onDelete('cascade')->onUpdate('cascade');
            $table->foreign('company_id')->references('id')->on('companies')
                    ->onDelete('cascade')->onUpdate('cascade');
            $table->foreign('document_type_id')->references('id')->on('document_types')
                    ->onDelete('cascade')->onUpdate('cascade');
            $table->foreign('reviewed_by')->references('id')->on('users')
                    ->onDelete('set null')->onUpdate('set null');
            $table->timestamps();
        });
    }

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