<?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('artworks', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->index();

            $table->string('title', 150);
            $table->string('slug', 160)->index();
            $table->text('description')->nullable();

            $table->string('file_name');
            $table->string('file_path');
            $table->unsignedBigInteger('file_size');
            $table->string('mime_type', 64);

            $table->unsignedInteger('width');
            $table->unsignedInteger('height');

            $table->boolean('is_public')->default(true)->index();
            $table->boolean('is_approved')->default(false)->index();
            $table->timestamp('published_at')->nullable()->index();

            $table->timestamps();
            $table->softDeletes();

            $table->index(['is_public', 'is_approved', 'published_at'], 'idx_artworks_browse');
        });
    }

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