<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('activities', function (Blueprint $table) {
            $table->id();
            $table->uuid('uuid')->unique();
            $table->foreignId('academy_id')->constrained('academies');
            $table->string('name', 255);
            $table->string('name_ar', 255);
            $table->string('slug', 100);
            $table->text('description')->nullable();
            $table->text('description_ar')->nullable();
            $table->string('icon', 100)->nullable();
            $table->string('color', 7)->nullable();
            $table->string('category', 20)->default('sport');
            $table->boolean('is_active')->default(true);
            $table->integer('sort_order')->default(0);
            $table->jsonb('metadata')->default('{}');
            $table->timestamps();

            $table->unique(['academy_id', 'slug']);
            $table->index(['academy_id', 'is_active']);
        });

        DB::statement("ALTER TABLE activities ADD CONSTRAINT activities_category_check CHECK (category IN ('sport', 'art', 'academic', 'fitness', 'other'))");
    }

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