<?php

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

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('attendances', function (Blueprint $table) {
            $table
                ->bigInteger('employee_id')
                ->unsigned()
                ->after('id');
            $table->date('date')->after('employee_id');
            $table
                ->bigInteger('land_id')
                ->unsigned()
                ->nullable()
                ->after('date');
            $table
                ->bigInteger('work_type_id')
                ->unsigned()
                ->nullable()
                ->after('land_id');
            $table->boolean('present')->nullable()
                        ->after('work_type_id');
            $table
                ->foreign('employee_id')
                ->references('id')
                ->on('employees')
                ->onDelete('cascade')
                ->onUpdate('cascade');
            $table
                ->foreign('land_id')
                ->references('id')
                ->on('lands')
                ->onDelete('cascade')
                ->onUpdate('cascade');
            $table
                ->foreign('work_type_id')
                ->references('id')
                ->on('work_types')
                ->onDelete('cascade')
                ->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('attendances', function (Blueprint $table) {
            $table->dropColumn('employee_id');
            $table->dropColumn('date');
            $table->dropColumn('land_id');
            $table->dropColumn('work_type_id');
            $table->dropColumn('present');
            $table->dropForeign('attendances_employee_id_foreign');
            $table->dropForeign('attendances_land_id_foreign');
            $table->dropForeign('attendances_work_type_id_foreign');
        });
    }
};
