<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateAscClasses extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'import_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
            ],
            'asc_id' => [
                'type'       => 'VARCHAR',
                'constraint' => 50,
                'comment'    => 'ID asli dari XML aSc',
            ],
            'name' => [
                'type'       => 'VARCHAR',
                'constraint' => 50,
                'comment'    => 'Misal: 7A, 8B, 9A1',
            ],
            'short_name' => [
                'type'       => 'VARCHAR',
                'constraint' => 20,
            ],
            'grade_level' => [
                'type'       => 'TINYINT',
                'constraint' => 2,
                'null'       => true,
                'comment'    => '7, 8, atau 9 — diambil dari prefix nama kelas',
            ],
            // Untuk mapping ke data asli aplikasi (nanti)
            'classroom_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
                'null'       => true,
                'default'    => null,
                'comment'    => 'FK ke classrooms (nanti)',
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addKey('import_id');
        $this->forge->addKey('asc_id');
        $this->forge->createTable('asc_classes');
    }

    public function down()
    {
        $this->forge->dropTable('asc_classes');
    }
}