<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * Creates the training_packages table to store training program information
     * including name, description, duration, fees, capacity, and status.
     *
     * @return void
     */
    public function up(): void
    {
        Schema::create('training_packages', function (Blueprint $table) {
            $table->id();
            
            // Basic Information
            $table->string('name', 191);
            $table->text('description')->nullable();
            $table->text('learning_objectives')->nullable();
            $table->text('prerequisites')->nullable();
            
            // Duration and Capacity
            $table->integer('duration_hours')->default(0);
            $table->integer('duration_days')->default(0);
            $table->integer('capacity')->default(50);
            
            // Fee Information
            $table->decimal('fee_amount', 10, 2)->default(0.00);
            $table->string('currency', 3)->default('UGX');
            $table->boolean('is_free')->default(false);
            
            // Certificate Settings
            $table->enum('certificate_format', ['portrait', 'landscape'])->default('portrait');
            $table->boolean('generates_certificate')->default(true);
            
            // Status and Visibility
            $table->enum('status', ['draft', 'active', 'inactive', 'archived'])->default('draft');
            $table->boolean('is_public')->default(true);
            $table->boolean('requires_approval')->default(true);
            
            // Category and Tags
            $table->foreignId('category_id')->nullable()->constrained('training_categories')->nullOnDelete();
            $table->json('tags')->nullable();
            
            // Featured Image
            $table->string('featured_image')->nullable();
            
            // Audit Fields
            $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
            $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
            
            // Soft Delete and Timestamps
            $table->softDeletes();
            $table->timestamps();
            
            // Indexes
            $table->index('status');
            $table->index('is_public');
            $table->index('created_by');
            $table->index('created_at');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down(): void
    {
        Schema::dropIfExists('training_packages');
    }
};
