<?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('push_subscriptions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->string('endpoint', 1024);
            $table->string('endpoint_hash', 64);
            $table->string('p256dh', 255);
            $table->string('auth', 255);
            $table->string('user_agent')->nullable();
            $table->timestamp('created_at')->useCurrent();
            $table->unique(['user_id', 'endpoint_hash']);
            $table->index('user_id');
        });
    }

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

