<?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('episodes', function (Blueprint $table) {
            $table->id();
            $table->foreignId('series_id')->constrained('series')->onDelete('cascade');
            $table->foreignId('season_id')->constrained('seasons')->onDelete('cascade');
            $table->unsignedSmallInteger('episode_number');
            $table->string('title', 255);
            $table->text('description')->nullable();
            $table->string('thumbnail_image')->nullable();
            $table->enum('video_type', ['upload', 'youtube', 'other'])->default('upload');
            $table->string('youtube_url', 255)->nullable();
            $table->string('other_url', 255)->nullable();
            $table->string('video', 255)->nullable();
            $table->unsignedInteger('duration_seconds')->default(0);
            $table->integer('total_views')->default(0);
            $table->boolean('is_premium')->default(false);
            $table->unsignedTinyInteger('status')->default(0)->comment('0: active, 1: inactive');
            $table->timestamps();

            $table->unique(['season_id', 'episode_number']);
            $table->index(['series_id', 'season_id']);
        });
    }

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