<?php
// database/migrations/xxxx_xx_xx_xxxxxx_create_product_stock_snapshots_table.php

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

class CreateProductStockSnapshotsTable extends Migration
{
    public function up()
    {
        Schema::create('product_stock_snapshots', function (Blueprint $table) {
            $table->id();
            $table->foreignId('product_id')->constrained('product')->onDelete('cascade');
            $table->integer('current_stock');
            $table->date('snapshot_date');
            $table->text('notes')->nullable();
            $table->timestamps();
            
            $table->unique(['product_id', 'snapshot_date']);
            $table->index('snapshot_date');
        });
    }

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