<?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('import_jobs', function (Blueprint $table) {
            $table->id();
            $table->string('source_url')->nullable();
            $table->string('watch_id')->nullable();
            $table->string('cdn_id')->nullable();           // 85937 — XDM'den alınan CDN ID
            $table->string('anime_title')->nullable();
            $table->foreignId('anime_id')->nullable()->constrained('animes')->nullOnDelete();
            // Sezon/bölüm aralıkları (JSON array: [{"season":1,"from":1,"to":24}])
            $table->json('season_ranges')->nullable();
            $table->enum('status', ['pending','fetching','downloading','uploading','done','failed'])->default('pending');
            $table->integer('total_episodes')->default(0);
            $table->integer('done_episodes')->default(0);
            $table->integer('failed_episodes')->default(0);
            $table->text('current_step')->nullable();
            $table->text('error_log')->nullable();
            $table->timestamps();
        });
    }

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