<?php

declare(strict_types=1);

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('bandwidth_usage', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('service_id')->constrained()->cascadeOnDelete();
            $table->timestamp('period_start');
            $table->timestamp('period_end');
            $table->unsignedBigInteger('bytes_in')->default(0);
            $table->unsignedBigInteger('bytes_out')->default(0);
            $table->unsignedBigInteger('total_bytes')->default(0);
            $table->unsignedBigInteger('quota_bytes')->default(0);
            $table->unsignedBigInteger('overage_bytes')->default(0);
            $table->decimal('overage_charge', 10, 2)->default(0);
            $table->string('source')->default('elastiflow');
            $table->timestamps();

            $table->index(['service_id', 'period_start']);
        });
    }

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