<?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_performances', function (Blueprint $table) {
            $table->id();
            $table->foreignId('technician_id')->constrained()->onDelete('cascade');
            $table->date('performance_date');
            $table->string('metric_type'); // jobs_completed, hours_worked, revenue_generated, customer_rating, etc.
            $table->decimal('metric_value', 10, 2);
            $table->string('period_type')->default('daily'); // daily, weekly, monthly, quarterly, yearly
            $table->json('additional_data')->nullable(); // store complex performance data
            $table->text('notes')->nullable();
            $table->timestamps();

            $table->index(['technician_id', 'performance_date']);
            $table->index(['metric_type', 'period_type']);
            $table->index('performance_date');
        });
    }

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