<?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_by_utm', function (Blueprint $table) {
            $table->id();
            $table->foreignId('link_id')->constrained()->cascadeOnDelete();
            $table->date('day');
            $table->string('utm_source', 128)->default('');
            $table->string('utm_medium', 128)->default('');
            $table->string('utm_campaign', 128)->default('');
            $table->unsignedBigInteger('count')->default(0);
            $table->unique(['link_id', 'day', 'utm_source', 'utm_medium', 'utm_campaign'], 'clicks_by_utm_unique');
            $table->index(['link_id', 'day']);
        });
    }

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