<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up()
    {
        Schema::create('video_views', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->foreignId('video_id')->constrained()->onDelete('cascade');
            $table->timestamp('watched_at')->useCurrent();
            
            $table->index(['user_id', 'watched_at']);
            $table->index(['video_id', 'watched_at']);
        });
    }

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

