<?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('technician_workloads', function (Blueprint $table) {
            $table->id();
            $table->foreignId('technician_id')->constrained()->onDelete('cascade');
            $table->date('workload_date');
            $table->decimal('scheduled_hours', 5, 2)->default(0);
            $table->decimal('actual_hours', 5, 2)->default(0);
            $table->decimal('billable_hours', 5, 2)->default(0);
            $table->integer('jobs_assigned')->default(0);
            $table->integer('jobs_completed')->default(0);
            $table->integer('jobs_in_progress')->default(0);
            $table->decimal('utilization_rate', 5, 2)->default(0); // percentage
            $table->decimal('efficiency_rate', 5, 2)->default(0); // percentage
            $table->text('notes')->nullable();
            $table->timestamps();

            $table->unique(['technician_id', 'workload_date']);
            $table->index('workload_date');
            $table->index(['technician_id', 'workload_date']);
        });
    }

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