<?php

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

return new class extends Migration
{
    public function up(): void
    {
        // Add unit_price to orders
        Schema::table('orders', function (Blueprint $table) {
            if (!Schema::hasColumn('orders', 'unit_price')) {
                $table->decimal('unit_price', 10, 2)->nullable()->after('quantity');
            }
        });

        // Drop price from fibre_types if exists
        Schema::table('fibre_types', function (Blueprint $table) {
            if (Schema::hasColumn('fibre_types', 'price')) {
                $table->dropColumn('price');
            }
        });
    }

    public function down(): void
    {
        // Re-add price to fibre_types
        Schema::table('fibre_types', function (Blueprint $table) {
            if (!Schema::hasColumn('fibre_types', 'price')) {
                $table->decimal('price', 10, 2)->nullable()->after('name');
            }
        });

        // Drop unit_price from orders
        Schema::table('orders', function (Blueprint $table) {
            if (Schema::hasColumn('orders', 'unit_price')) {
                $table->dropColumn('unit_price');
            }
        });
    }
};


