<?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('meal_posts', function (Blueprint $table) {
            $table->ulid('id')->primary();
            $table->foreignUlid('user_id')->constrained('users')->cascadeOnDelete();
            $table->string('image_url', 2048);
            $table->text('caption')->nullable();
            $table->integer('calories')->nullable();
            $table->decimal('proteins', 8, 2)->nullable();
            $table->decimal('carbs', 8, 2)->nullable();
            $table->decimal('fats', 8, 2)->nullable();
            $table->string('diet_type')->default('omnivore');
            $table->boolean('ai_generated')->default(false)->index();
            $table->string('title');
            $table->string('type')->default('breakfast');
            $table->string('visibility', 20)->default('private')->index();
            $table->timestamp('hidden_at')->nullable()->after('deleted_at')->index();
            $table->foreignUlid('hidden_by')->nullable()->after('hidden_at')->constrained('users')->nullOnDelete();
            $table->text('hidden_reason')->nullable()->after('hidden_by');
            $table->timestamp('eaten_at');
            $table->timestamps();
            $table->softDeletes();
        });
    }

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