<?php

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

    return new class extends Migration
    {
        public function up()
        {
            Schema::create('authorizations', function (Blueprint $table) {
                $table->id();
                $table->foreignId('permohonan_id')->constrained('permohonan')->onDelete('cascade');
                $table->string('jenis');

                // SO fields
                $table->boolean('approve_so')->default(false);
                $table->string('status_so')->nullable();
                $table->text('keterangan_so')->nullable();
                $table->timestamp('approve_so_at')->nullable();

                // EO fields
                $table->boolean('approve_eo')->default(false);
                $table->string('status_eo')->nullable();
                $table->text('keterangan_eo')->nullable();
                $table->timestamp('approve_eo_at')->nullable();

                // DD fields
                $table->boolean('approve_dd')->default(false);
                $table->string('status_dd')->nullable();
                $table->text('keterangan_dd')->nullable();
                $table->timestamp('approve_dd_at')->nullable();

                $table->string('status')->nullable();
                $table->text('keterangan')->nullable();
                $table->text('request')->nullable();
                $table->text('alasan')->nullable();
                $table->foreignId('user_id')->nullable()->constrained('users')->onDelete('set null');

                $table->timestamps();
            });
        }

        public function down()
        {
            Schema::dropIfExists('authorizations');
        }
    };
