<?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('kitchen_stock_items', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('hotel_id')->nullable()->index();
            $table->string('name');
            $table->string('category', 40)->nullable(); // Soups|Proteins|Grains|Vegetables|Dairy|Other
            $table->string('location', 20)->default('store'); // fridge|freezer|pot|store|shelf|prep
            $table->string('unit', 20)->default('portions'); // portions|litres|kg|pcs|bowls
            $table->decimal('quantity', 10, 2)->default(0);
            $table->decimal('par_level', 10, 2)->default(0); // reorder threshold
            $table->unsignedBigInteger('menu_item_id')->nullable()->index();
            $table->string('status', 15)->default('active');
            $table->string('notes')->nullable();
            $table->timestamps();
        });

        Schema::create('kitchen_stock_logs', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('hotel_id')->nullable()->index();
            $table->unsignedBigInteger('kitchen_stock_item_id')->index();
            $table->unsignedBigInteger('user_id')->nullable();
            $table->string('change_type', 15); // set|add|deduct|waste
            $table->decimal('quantity_before', 10, 2);
            $table->decimal('quantity_after', 10, 2);
            $table->string('reason')->nullable();
            $table->text('shift_note')->nullable();
            $table->timestamps();
        });
    }

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