<?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('productivity_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->foreignId('task_id')->nullable()->constrained()->nullOnDelete();
            $table->foreignId('daily_work_log_id')->nullable()->constrained('daily_work_logs')->nullOnDelete();
            $table->date('log_date');
            $table->unsignedInteger('estimated_seconds')->default(0);
            $table->unsignedInteger('actual_seconds')->default(0);
            $table->unsignedInteger('idle_seconds')->default(0);
            $table->decimal('productivity_score', 5, 2)->default(0);
            $table->text('remarks')->nullable();
            $table->timestamps();
            $table->softDeletes();
            $table->index(['user_id', 'log_date']);
        });
    }

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