<?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('attendance_punch_details', function (Blueprint $table) {
            $table->id();

            $table->foreignId('attendance_detail_id')
                ->constrained('attendance_details')
                ->cascadeOnDelete();

            // Order of punches (1st in, 1st out, 2nd in...)
            $table->unsignedTinyInteger('sequence_no');

            $table->enum('punch_type', ['IN', 'OUT']);
            $table->dateTime('punch_time');

            // Source
            $table->enum('source', ['BIOMETRIC', 'MANUAL', 'IMPORT'])
                ->default('BIOMETRIC');

            $table->timestamps();

            $table->index(['attendance_detail_id', 'sequence_no']);
        });

    }

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