<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateAscTeachers 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' => 150,
            ],
            'short_code' => [
                'type'       => 'VARCHAR',
                'constraint' => 10,
                'comment'    => 'Kode guru, misal: 01, 02, 32',
            ],
            'gender' => [
                'type'       => 'ENUM',
                'constraint' => ['M', 'F'],
                'default'    => 'M',
            ],
            'color' => [
                'type'       => 'VARCHAR',
                'constraint' => 10,
                'default'    => '#CCCCCC',
                'comment'    => 'Warna unik guru dari XML, misal: #FF0000',
            ],
            // Untuk mapping ke data asli aplikasi (nanti)
            'teacher_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
                'null'       => true,
                'default'    => null,
                'comment'    => 'FK ke teachers (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_teachers');
    }

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