<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddStaffFieldsToTeachers extends Migration
{
    public function up()
    {
        if (!$this->db->fieldExists('jabatan', 'teachers')) {
            $this->forge->addColumn('teachers', [
                'jabatan' => [
                    'type'       => 'VARCHAR',
                    'constraint' => 100,
                    'null'       => true,
                    'default'    => null,
                    'comment'    => 'Jabatan, contoh: Pendidik/Guru, Staff TU/Tenaga Kependidikan',
                    'after'      => 'golongan',
                ],
            ]);
        }
        if (!$this->db->fieldExists('status_kepegawaian', 'teachers')) {
            $this->forge->addColumn('teachers', [
                'status_kepegawaian' => [
                    'type'       => 'VARCHAR',
                    'constraint' => 50,
                    'null'       => true,
                    'default'    => null,
                    'comment'    => 'Status Kepegawaian: PNS, PPPK, Honorer',
                    'after'      => 'jabatan',
                ],
            ]);
        }
        if (!$this->db->fieldExists('is_sertifikasi', 'teachers')) {
            $this->forge->addColumn('teachers', [
                'is_sertifikasi' => [
                    'type'       => 'TINYINT',
                    'constraint' => 1,
                    'null'       => false,
                    'default'    => 0,
                    'comment'    => 'Status Sertifikasi: 1 = Sudah, 0 = Belum',
                    'after'      => 'status_kepegawaian',
                ],
            ]);
        }
    }

    public function down()
    {
        $this->forge->dropColumn('teachers', ['jabatan', 'status_kepegawaian', 'is_sertifikasi']);
    }
}
