<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('bill_items', function (Blueprint $table) {
            $table->id();
            $table->foreignId('bill_id')->constrained('bills')->onDelete('cascade');
            $table->integer('product_id')->unsigned(); // Matches product_id in products table
            $table->string('product_description')->nullable();
            $table->decimal('price', 10, 2)->default(0.00); // Original product price
            $table->decimal('our_price', 10, 2)->default(0.00); // Selling price
            $table->integer('qty')->default(1);
            $table->decimal('amount', 10, 2)->default(0.00); // our_price * qty
            $table->timestamps();

            $table->foreign('product_id')->references('product_id')->on('products')->onDelete('cascade');
        });
    }

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