<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

/**
 * BATCH 3 — T-08
 * ptm_teacher_profiles: Extension 1-to-1 dari tabel teachers SIMAK.
 * Menyimpan data profesional guru khusus untuk domain PTM.
 */
class CreatePtmTeacherProfiles extends Migration
{
    public function up(): void
    {
        $this->forge->addField([
            'id'                  => ['type' => 'INT',     'constraint' => 10,  'unsigned' => true, 'auto_increment' => true],
            'teacher_id'          => ['type' => 'BIGINT',  'constraint' => 20,  'unsigned' => true, 'null' => false, 'comment' => 'FK ke teachers.id (SIMAK) — 1-to-1'],
            'nuptk'               => ['type' => 'VARCHAR', 'constraint' => 20,  'null' => true, 'comment' => 'Nomor Unik Pendidik dan Tenaga Kependidikan'],
            'jenis_kepegawaian'   => ['type' => 'ENUM', 'constraint' => ['PNS','PPPK','GTY','GTT','HONOR'], 'null' => true, 'comment' => 'Karakteristik kepegawaian (ADR-001)'],
            'pendidikan_terakhir' => ['type' => 'ENUM', 'constraint' => ['SMA','D3','S1','S2','S3','LAINNYA'], 'null' => true],
            'bidang_studi_ijazah' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true],
            'institusi_ijazah'    => ['type' => 'VARCHAR', 'constraint' => 200, 'null' => true],
            'tahun_lulus'         => ['type' => 'YEAR',    'null' => true],
            'created_at'          => ['type' => 'DATETIME', 'null' => true],
            'updated_at'          => ['type' => 'DATETIME', 'null' => true],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addUniqueKey('teacher_id');
        $this->forge->addKey('jenis_kepegawaian');
        $this->forge->addForeignKey('teacher_id', 'teachers', 'id', 'RESTRICT', 'CASCADE');
        $this->forge->createTable('ptm_teacher_profiles', true);
    }

    public function down(): void
    {
        $this->forge->dropTable('ptm_teacher_profiles', true);
    }
}
