<?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
    {
        // Kita drop dulu tabel lama biar bersih, lalu buat ulang sesuai struktur baru
        Schema::dropIfExists('learning_modules');

        Schema::create('learning_modules', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->foreignId('subject_id')->constrained('subjects')->onDelete('cascade');
            
            // Identitas Umum
            $table->string('grade_level'); // Kelas (X, XI, XII)
            $table->string('semester');
            $table->json('profil_pelajar_pancasila')->nullable(); // Multi-select (JSON)
            
            // Detail Pertemuan
            $table->string('elemen')->nullable();
            $table->integer('meeting_sequence'); // Pertemuan Ke-
            $table->integer('allocation_jp'); // Jumlah JP
            $table->integer('duration_minutes'); // Durasi Menit
            
            // Komponen Kurikulum (Diambil dari input sebelumnya)
            $table->text('cp_text'); // Capaian Pembelajaran (Bisa text panjang)
            $table->text('tp_text'); // Tujuan Pembelajaran
            $table->string('topic'); // Topik
            
            // Metodologi (Referensi)
            $table->string('model_learning')->nullable(); // Model
            $table->string('method_learning')->nullable(); // Metode
            $table->string('approach_learning')->nullable(); // Pendekatan
            $table->string('strategy_learning')->nullable(); // Strategi
            $table->string('partnership')->nullable(); // Kemitraan (Opsional)
            
            // Lingkungan
            $table->text('learning_environment')->nullable();
            $table->text('digital_usage')->nullable();
            
            // Kegiatan Pembelajaran (Detail Sesuai Gambar)
            $table->longText('activity_initial'); // Kegiatan Awal
            $table->longText('activity_core_understand'); // Inti - Memahami
            $table->longText('activity_core_apply'); // Inti - Mengaplikasi
            $table->longText('activity_core_reflect'); // Inti - Merefleksi
            $table->longText('activity_closing'); // Penutup
            
            $table->timestamps();
        });
    }

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