<?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('clicks_hourly', function (Blueprint $table) {
            $table->id();
            $table->foreignId('link_id')->constrained()->cascadeOnDelete();
            $table->timestamp('hour');
            $table->string('country', 2)->default('');
            $table->enum('device', ['desktop', 'mobile', 'tablet', 'bot', 'unknown'])->default('unknown');
            $table->unsignedBigInteger('count')->default(0);
            $table->unsignedBigInteger('unique_visitors')->default(0);
            $table->unique(['link_id', 'hour', 'country', 'device']);
            $table->index(['link_id', 'hour']);
        });
    }

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