<?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('network_sessions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('subscriber_id')->nullable()->constrained('subscribers')->onDelete('cascade');
            $table->string('username');
            $table->string('type')->default('PPPoE'); // PPPoE, Hotspot
            $table->foreignId('router_id')->nullable()->constrained('routers')->onDelete('set null');
            $table->string('ip_address');
            $table->string('mac_address');
            $table->bigInteger('upload_bytes')->default(0);
            $table->bigInteger('download_bytes')->default(0);
            $table->integer('duration_seconds')->default(0);
            $table->string('status')->default('Active');
            $table->timestamp('started_at');
            $table->timestamps();
        });
    }

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