<?php

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

return new class extends Migration
{
    /**
     * Tambah kolom void approval workflow ke tabel sales.
     */
    public function up(): void
    {
        Schema::table('sales', function (Blueprint $table) {
            $table->enum('void_status', ['pending', 'approved', 'rejected'])->nullable()->after('void_reason');
            $table->foreignId('void_requested_by')->nullable()->constrained('users')->nullOnDelete()->after('void_status');
            $table->timestamp('void_requested_at')->nullable()->after('void_requested_by');
            $table->foreignId('void_approved_by')->nullable()->constrained('users')->nullOnDelete()->after('void_requested_at');
            $table->text('void_rejected_reason')->nullable()->after('void_approved_by');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('sales', function (Blueprint $table) {
            $table->dropForeign(['void_requested_by']);
            $table->dropForeign(['void_approved_by']);
            $table->dropColumn([
                'void_status',
                'void_requested_by',
                'void_requested_at',
                'void_approved_by',
                'void_rejected_reason',
            ]);
        });
    }
};
