<?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('nutrition_items', function (Blueprint $table) {
            $table->id();
            $table->foreignId('nutrition_meal_id')->constrained('nutrition_meals')->cascadeOnDelete();

            $table->string('food_name', 150);
            $table->decimal('amount', 8, 2)->nullable();
            $table->enum('unit', ['gram', 'kg', 'ml', 'liter', 'cup', 'tablespoon', 'teaspoon', 'piece', 'slice', 'other'])
                ->default('gram');
            $table->unsignedInteger('calories')->nullable();
            $table->text('notes')->nullable();
            $table->unsignedInteger('sort_order')->default(0);

            $table->timestamps();
            $table->softDeletes();

            $table->index(['nutrition_meal_id', 'sort_order']);
        });
    }

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