<?php

use App\Models\OrderManagement\Order;
use App\Models\OrderManagement\BillingDesk;
use App\Models\ProductManagement\Product;
use App\Models\StockManagement\Warehouse;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\PaymentManagement\PaymentMethod;

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()  {

        $from_table1 = "order_mgt__point_of_sales";
        $to_table1 = "order_mgt__billing_desks";

        $from_table2 = "order_mgt__point_of_sales_has_users";
        $to_table2 = "order_mgt__billing_desks_has_users";


        if (Schema::hasTable($from_table1)){
            Schema::rename($from_table1,$to_table1);
        }
        if (Schema::hasTable($from_table2)){
            Schema::rename($from_table2,$to_table2);
        }

        Schema::whenTableHasColumn($to_table2, "point_of_sale_id",function (Blueprint $table)  {
            $table->renameColumn("point_of_sale_id","billing_desk_id")
                  ->comment("[FK] La caisse de facturation associé");
        });

        Schema::whenTableHasColumn((new Order)->getTable(), "point_of_sale_id",function (Blueprint $table)  {
            $table->renameColumn("point_of_sale_id","billing_desk_id")
                ->comment("[FK] La caisse de facturation associé");

        });



    }

};
