<?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('animes', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->string('title_en')->nullable();
            $table->string('title_jp')->nullable();
            $table->string('slug')->unique();
            $table->text('description')->nullable();
            $table->string('cover_image')->nullable();
            $table->string('banner_image')->nullable();
            $table->string('trailer_url')->nullable();
            $table->integer('release_year')->nullable();
            $table->enum('type', ['series', 'movie', 'ova', 'ona', 'special'])->default('series');
            $table->enum('status', ['ongoing', 'completed', 'upcoming'])->default('ongoing');
            $table->integer('episode_count')->default(0);
            $table->decimal('rating', 3, 1)->default(0);
            $table->string('studio')->nullable();
            $table->string('mal_id')->nullable(); // MyAnimeList ID
            $table->boolean('is_featured')->default(false);
            $table->boolean('is_published')->default(false);
            $table->timestamps();
        });

        Schema::create('anime_genre', function (Blueprint $table) {
            $table->foreignId('anime_id')->constrained()->onDelete('cascade');
            $table->foreignId('genre_id')->constrained()->onDelete('cascade');
            $table->primary(['anime_id', 'genre_id']);
        });
    }

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