<?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('sale_packs', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('sale_id')->constrained()->cascadeOnDelete();
            $table->foreignId('factory_product_id')->constrained()->cascadeOnDelete();
            $table->foreignId('customer_order_item_id')->nullable()->constrained()->nullOnDelete();
            $table->decimal('pack_weight', 12, 3);
            $table->date('expiry_date');
            $table->foreignId('original_sale_pack_id')->nullable()->constrained('sale_packs')->nullOnDelete();
            $table->boolean('is_returned')->default(false);
            $table->timestamps();
        });
    }

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