<?php

use App\Models\{ItemDetail, Meal, Product, User};
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('item_details', function (Blueprint $table) {
            $table->id();
            $table->foreignIdFor(User::class)->constrained()->cascadeOnDelete();
            $table->foreignIdFor(Product::class)->constrained()->cascadeOnDelete();
            $table->integer('number_of_servings')->default(1);
            $table->string('unit')->default('gram');
            $table->float('number_of_unit')->default(1);
            $table->integer('calories')->nullable();
            $table->integer('carb')->nullable();
            $table->integer('protein')->nullable();
            $table->integer('fat')->nullable();
            $table->timestamps();
        });

        Schema::create('meal_items', function (Blueprint $table) {
            $table->id();
            $table->foreignIdFor(Meal::class)->constrained()->cascadeOnDelete();
            $table->foreignIdFor(User::class)->constrained()->cascadeOnDelete();
            $table->foreignIdFor(ItemDetail::class)->constrained()->cascadeOnDelete();
            $table->date('date')->nullable();
            $table->integer('calories')->nullable();
            $table->integer('carb')->nullable();
            $table->integer('protein')->nullable();
            $table->integer('fat')->nullable();
            $table->timestamps();
        });

        Schema::create('schedule_details', function (Blueprint $table) {
            $table->id();
            $table->foreignIdFor(User::class)->constrained()->cascadeOnDelete();
            $table->date('date')->nullable();
            $table->integer('calories')->nullable();
            $table->integer('carb')->nullable();
            $table->integer('protein')->nullable();
            $table->integer('fat')->nullable();
            $table->timestamps();
        });

        
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('schedule_details');
        Schema::dropIfExists('meal_items');
        Schema::dropIfExists('item_details');
    }
};
