<?php

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::table('sales_return_masters', function (Blueprint $table) {
            $table->string('return_type')->nullable()->default('cash')->after('location_id'); // 'cash' | 'exchange'
            $table->unsignedBigInteger('exchange_id')->nullable()->after('return_type');
            $table->foreign('exchange_id')->references('id')->on('sales_masters')->onDelete('set null');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('sales_return_masters', function (Blueprint $table) {
            $table->dropForeign(['exchange_id']);
            $table->dropColumn(['exchange_id', 'return_type']);
        });
    }
};
