<?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
    {
        Schema::table('sales', function (Blueprint $table) {
            $table->foreignId('seller_user_id')->nullable()->constrained('users')->nullOnDelete()->after('owner_user_id');
            $table->decimal('sales_commission_pct', 5, 2)->nullable()->after('platform_fee')
                ->comment('Si null, usa el % por defecto de system_settings');
        });
    }

    public function down(): void
    {
        Schema::table('sales', function (Blueprint $table) {
            $table->dropForeign(['seller_user_id']);
            $table->dropColumn(['seller_user_id', 'sales_commission_pct']);
        });
    }
};
