<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('wip_entries', function (Blueprint $table) {
            $table->id();
        
            $table->foreignId('solicitor_id')->constrained()->cascadeOnDelete();
            $table->foreignId('client_id')->nullable()->constrained('clients')->nullOnDelete();
            $table->foreignId('claim_id')->nullable()->constrained('claims')->nullOnDelete();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
        
            $table->nullableMorphs('source');
        
            $table->string('activity_type'); // email, note, dsar, manual
            $table->unsignedInteger('seconds')->default(0);
            $table->unsignedInteger('units')->default(1);
            $table->decimal('hours', 8, 2)->default(0);
        
            $table->text('description')->nullable();
        
            $table->timestamp('started_at')->nullable();
            $table->timestamp('ended_at')->nullable();
        
            $table->boolean('is_manual')->default(false);
        
            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('wip_entries');
    }
};
