<?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::table('video_views', function (Blueprint $table) {
            $table->string('device_hash', 64)->nullable()->after('device_id');
            $table->index(['video_id', 'device_hash']);
        });

        Schema::table('video_downloads', function (Blueprint $table) {
            $table->string('device_hash', 64)->nullable()->after('user_agent');
        });

        Schema::table('share_accesses', function (Blueprint $table) {
            $table->string('device_hash', 64)->nullable()->after('user_agent');
        });
    }

    public function down(): void
    {
        Schema::table('video_views', function (Blueprint $table) {
            $table->dropIndex(['video_id', 'device_hash']);
            $table->dropColumn('device_hash');
        });
        Schema::table('video_downloads', function (Blueprint $table) {
            $table->dropColumn('device_hash');
        });
        Schema::table('share_accesses', function (Blueprint $table) {
            $table->dropColumn('device_hash');
        });
    }
};
