<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('attendances', function (Blueprint $table) {
            $table->id();
            $table->foreignId('customer_id')->constrained()->onDelete('cascade');
            $table->foreignId('subscription_id')->nullable()->constrained();
            $table->dateTime('check_in');
            $table->dateTime('check_out')->nullable();
            $table->enum('status', ['checked_in', 'checked_out', 'absent'])->default('checked_in');
            $table->enum('type', ['normal', 'trial', 'guest'])->default('normal');
            $table->integer('duration')->nullable(); // مدة الجلسة بالدقائق
            $table->foreignId('checked_in_by')->nullable()->constrained('users');
            $table->foreignId('checked_out_by')->nullable()->constrained('users');
            $table->text('notes')->nullable();
            $table->timestamps();

            // فهارس للبحث السريع
            $table->index(['customer_id', 'check_in']);
            $table->index('status');
            $table->index('check_in');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('attendances');
    }
};
