<?php

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

class CreateDriverIncentivesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('driver_incentives', function (Blueprint $table) {
            $table->id(); // Primary key (auto-incrementing ID)
            
            // Modify driver_id to be a string type to support custom user_id format like 'CleaneoVendor000001'
            $table->string('driver_id');
            
            // Set driver_id as a foreign key referencing the user_id column in the users table
            $table->foreign('driver_id')->references('user_id')->on('users')->onDelete('cascade');
            
            // Assuming the order_id is an integer and refers to the orders table
            $table->foreignId('order_id')->constrained('orders')->onDelete('cascade');
            
            $table->decimal('amount', 10, 2); // Incentive amount (decimal with 2 decimal places)
            $table->timestamps(); // created_at and updated_at timestamps
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('driver_incentives');
    }
}
