<?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::create('payments', function (Blueprint $table) {
            $table->id();
            $table->foreignId('invoice_id')
                  ->constrained()
                  ->cascadeOnDelete();
            $table->foreignId('consignment_id')
                  ->constrained()
                  ->cascadeOnDelete();
            $table->string('receipt_number')->unique();
            $table->decimal('amount_kes', 10, 2);
            $table->enum('method', ['cash', 'mpesa', 'bank', 'cheque']);
            $table->string('reference')->nullable();
            $table->text('notes')->nullable();
            $table->foreignId('cashier_id')
                  ->constrained('users')
                  ->restrictOnDelete();
            $table->timestamp('receipt_printed_at')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('payments');
    }
};