<?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('stock', function (Blueprint $table) {
            $table->id();
            $table->foreignId('product_id')->constrained('products')->cascadeOnDelete();
            $table->foreignId('store_id')->constrained('stores')->cascadeOnDelete();
            $table->integer('quantity')->default(0);
            $table->integer('reserved_quantity')->default(0);
            $table->integer('min_stock_level')->default(10);
            $table->integer('max_stock_level')->default(100);
            $table->timestamp('last_restocked_at')->nullable();
            $table->timestamp('last_sold_at')->nullable();
            $table->timestamps();
            
            $table->unique(['product_id', 'store_id']);
            $table->index('product_id');
            $table->index('store_id');
        });
    }

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