<?php

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

class CreateCompanyUserTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('company_user', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('company_id')->unsigned();
            $table->bigInteger('user_id')->unsigned();

            $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->bigInteger('job_position_id')->unsigned()->nullable();
            $table->enum('salary_type', ['1', '2', '3'])->nullable();
            $table->decimal('base_salary',10 ,2)->nullable();
            $table->decimal('performance_factor',10 ,2)->nullable(); //Factor prestacional 30%
            $table->decimal('salary',10 ,2)->nullable();
            $table->enum('payment_method', ['1', '2', '3', '4'])->nullable();
            $table->string('job_position_administrative_area',100)->nullable(); // solo para el area administrativa de la empresa
            $table->dateTime('initial_date_cv')->nullable(); // fecha de inicio de la actualización del curriculum, se actualiza al momento en que el empleado ingresa al modulo de hoja de vida
            $table->foreign('job_position_id')->references('id')->on('job_positions')
                ->onDelete('cascade')
                ->onUpdate('cascade');
            $table->timestamps();
        });
    }

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