<?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('portfolio_categories', function (Blueprint $table) {
            $table->id();
            $table->string('name');           // Брэндинг, Дижитал маркетинг, Продакшн, Арга хэмжээ
            $table->string('slug')->unique();
            $table->integer('sort_order')->default(0);
            $table->boolean('is_active')->default(true);
            $table->timestamps();
        });

        Schema::create('portfolios', function (Blueprint $table) {
            $table->id();
            $table->foreignId('category_id')
                  ->constrained('portfolio_categories')
                  ->cascadeOnDelete();
            $table->string('title');                           // ж: "OCOUTURE HIGH FASHION SHOW"
            $table->string('slug')->unique();
            $table->string('client_name')->nullable();         // ж: "APU Company"
            $table->string('subtitle')->nullable();            // "Reveal The Pride"
            $table->string('cover_image')->nullable();
            $table->json('gallery')->nullable();               // массив зурагнууд
            $table->longText('description')->nullable();
            $table->date('completed_at')->nullable();
            $table->string('external_url')->nullable();
            $table->boolean('is_featured')->default(false);
            $table->boolean('is_active')->default(true);
            $table->integer('sort_order')->default(0);
            $table->timestamps();

            $table->index(['is_active', 'is_featured']);
        });
    }

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