<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $episodes = DB::table('episode')->whereNull('download_url_4k')
            ->where('legacy_stream', 0)
            ->where('resolution', '4k')
            ->get();

        foreach ($episodes as $episode) {
            $episode->download_url_4k = Str::replace('1080p', '2160p', $episode->download_url);
            $episode->save();
        }
    }
};
