<?php

use App\ApprovalType;
use App\RecordAction;
use App\RecordStatus;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('data_changes', function (Blueprint $table) {
            $table->id();
            $table->string('connection_name')->nullable();
            $table->string('table_name')->nullable();
            $table->string('record_name')->nullable();
            $table->string('record_value')->nullable();
            $table->enum('action',RecordAction::values())->nullable();
            $table->string('subject')->nullable();

            $table->text('origins')->charset('binary')->nullable();
            $table->text('changes')->charset('binary')->nullable();
            $table->enum('status',RecordStatus::values())->default((RecordStatus::PENDNG)->value);
            $table->enum('type',ApprovalType::values())->default((ApprovalType::BATCH)->value);

            $table->text('api_url')->charset('binary')->nullable();
            $table->text('api_header')->charset('binary')->nullable();
            $table->text('api_body')->charset('binary')->nullable();

            $table->integer('created_by');
            $table->integer('approved_by')->nullable();
            $table->timestampTz('approved_at')->nullable();
            $table->integer('rejected_by')->nullable();
            $table->timestampTz('rejected_at')->nullable();

            $table->string('device_name')->nullable();
            $table->string('ip_address')->nullable();
            $table->string('os_version')->nullable();
            $table->timestampsTz();
        });
    }

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