<?php

declare(strict_types=1);

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('report_feeding_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('project_id')->constrained('projects')->cascadeOnDelete();
            $table->foreignId('report_id')->nullable()->constrained('reports')->nullOnDelete();
            $table->foreignId('feeding_meal_id')->nullable()->constrained('report_feeding_meals')->nullOnDelete();
            $table->date('fed_at_date');
            $table->string('meal_time', 20)->nullable();
            $table->string('meal_name')->nullable();
            $table->json('photos')->nullable();
            $table->text('notes')->nullable();
            $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();

            $table->index(['project_id', 'fed_at_date']);
        });
    }

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