<?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::table('office_locations', function (Blueprint $table) {
            if (!Schema::hasColumn('office_locations', 'max_gps_accuracy')) {
                $table->integer('max_gps_accuracy')->default(30)->after('radius_meters');
            }
        });

        Schema::table('attendances', function (Blueprint $table) {
            if (!Schema::hasColumn('attendances', 'accuracy_in')) {
                $table->double('accuracy_in')->nullable()->after('distance_in');
            }
            if (!Schema::hasColumn('attendances', 'accuracy_out')) {
                $table->double('accuracy_out')->nullable()->after('distance_out');
            }
            if (!Schema::hasColumn('attendances', 'qr_code_scanned')) {
                $table->string('qr_code_scanned')->nullable()->after('notes');
            }
        });
    }

    public function down(): void
    {
        Schema::table('office_locations', function (Blueprint $table) {
            if (Schema::hasColumn('office_locations', 'max_gps_accuracy')) {
                $table->dropColumn('max_gps_accuracy');
            }
        });

        Schema::table('attendances', function (Blueprint $table) {
            if (Schema::hasColumn('attendances', 'accuracy_in')) {
                $table->dropColumn(['accuracy_in', 'accuracy_out', 'qr_code_scanned']);
            }
        });
    }
};
