<?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_raw_punches', function (Blueprint $table) {
            $table->id();
            $table->foreignId('branch_id')->constrained()->cascadeOnDelete();
            $table->string('employee_code');
            $table->dateTime('punch_time');
            $table->string('punch_type')->nullable(); // IN, OUT
            $table->string('source')->nullable(); // CSV, API
            $table->foreignId('attendance_import_log_id')->nullable()->constrained('attendance_import_logs')->nullOnDelete();
            $table->timestamps();

            $table->index(['branch_id', 'employee_code', 'punch_time']);
        });
    }

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