<?php

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

class CreateCashCollectionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('cash_collections', function (Blueprint $table) {
            $table->id();
            $table->string('delivery_agent_id')->comment('References the driver’s unique user ID');
            $table->decimal('amount_collected', 10, 2)->comment('The total cash amount collected');
            $table->dateTime('date_of_submission')->comment('The date and time when the cash was submitted');
            $table->string('recipient')->comment('The person or entity receiving the cash submission');
            $table->timestamps();

            // Set up foreign key relationship for delivery_agent_id
            $table->foreign('delivery_agent_id')
                  ->references('user_id')
                  ->on('drivers')
                  ->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('cash_collections', function (Blueprint $table) {
            $table->dropForeign(['delivery_agent_id']);
        });

        Schema::dropIfExists('cash_collections');
    }
}
