<?php

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

class CreateWorkPermitsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('work_permits', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('type_work_permit_id');
            $table->unsignedBigInteger('company_id');
            $table->unsignedBigInteger('user_id');
            $table->dateTime('solicitation_date');
            $table->string('register_code');
            $table->dateTime('start_date');
            $table->dateTime('end_date');
            $table->text('observations')->nullable();
            $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->string('support_document')->nullable();
            $table->enum('status_support_document', ['0', '1', '2', '3'])->default('0');//0: Pendiente, 1: Aprobado, 2: Rechazado, 3: Solicitud de corrección
            $table->text('rejected_reason_support_document')->nullable();
            $table->foreign('type_work_permit_id')->references('id')->on('type_work_permits')
                    ->onDelete('cascade')->onUpdate('cascade');
            $table->foreign('user_id')->references('id')->on('users')
                    ->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('work_permits');
    }
}
