<?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('discovery_feedback_daily_metrics', function (Blueprint $table): void {
            $table->id();
            $table->date('metric_date');
            $table->string('algo_version', 64);
            $table->string('surface', 64);

            $table->unsignedInteger('views')->default(0);
            $table->unsignedInteger('clicks')->default(0);
            $table->unsignedInteger('favorites')->default(0);
            $table->unsignedInteger('downloads')->default(0);
            $table->unsignedInteger('feedback_actions')->default(0);
            $table->unsignedInteger('unique_users')->default(0);
            $table->unsignedInteger('unique_artworks')->default(0);

            $table->decimal('ctr', 8, 6)->default(0);
            $table->decimal('favorite_rate_per_click', 8, 6)->default(0);
            $table->decimal('download_rate_per_click', 8, 6)->default(0);
            $table->decimal('feedback_rate_per_click', 8, 6)->default(0);

            $table->timestamps();

            $table->unique(['metric_date', 'algo_version', 'surface'], 'discovery_feedback_daily_unique_idx');
            $table->index(['metric_date', 'algo_version', 'surface'], 'discovery_feedback_daily_lookup_idx');
        });
    }

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