<?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_daily', function (Blueprint $table) {
            $table->id();
            $table->foreignId('link_id')->constrained()->cascadeOnDelete();
            $table->date('day');
            $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', 'day', 'country', 'device']);
            $table->index(['link_id', 'day']);
        });
    }

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