<?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('academy_content_metrics_daily', function (Blueprint $table): void {
            $table->id();
            $table->date('date')->index();
            $table->string('content_type')->index();
            $table->unsignedBigInteger('content_id')->nullable()->index();
            $table->unsignedInteger('views')->default(0);
            $table->unsignedInteger('unique_visitors')->default(0);
            $table->unsignedInteger('guest_views')->default(0);
            $table->unsignedInteger('user_views')->default(0);
            $table->unsignedInteger('subscriber_views')->default(0);
            $table->unsignedInteger('engaged_views')->default(0);
            $table->unsignedInteger('scroll_50')->default(0);
            $table->unsignedInteger('scroll_75')->default(0);
            $table->unsignedInteger('scroll_100')->default(0);
            $table->unsignedInteger('likes')->default(0);
            $table->unsignedInteger('saves')->default(0);
            $table->unsignedInteger('prompt_copies')->default(0);
            $table->unsignedInteger('negative_prompt_copies')->default(0);
            $table->unsignedInteger('starts')->default(0);
            $table->unsignedInteger('completions')->default(0);
            $table->unsignedInteger('upgrade_clicks')->default(0);
            $table->unsignedInteger('premium_preview_views')->default(0);
            $table->unsignedInteger('search_impressions')->default(0);
            $table->unsignedInteger('search_clicks')->default(0);
            $table->unsignedInteger('bounce_count')->default(0);
            $table->unsignedInteger('avg_engaged_seconds')->nullable();
            $table->decimal('popularity_score', 12, 2)->default(0);
            $table->decimal('conversion_score', 12, 2)->default(0);
            $table->timestamps();

            $table->unique(['date', 'content_type', 'content_id'], 'academy_metrics_daily_unique');
        });
    }

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