<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('videos', function (Blueprint $table) {
            $table->string('download_access')->default('disabled')->after('allow_download');
        });

        // Migrate existing data
        DB::table('videos')->where('allow_download', true)->update(['download_access' => 'everyone']);

        Schema::table('videos', function (Blueprint $table) {
            $table->dropColumn('allow_download');
        });
    }

    public function down(): void
    {
        Schema::table('videos', function (Blueprint $table) {
            $table->boolean('allow_download')->default(false)->after('download_access');
        });

        DB::table('videos')->where('download_access', 'everyone')->update(['allow_download' => true]);

        Schema::table('videos', function (Blueprint $table) {
            $table->dropColumn('download_access');
        });
    }
};
