<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

/**
 * BATCH 1 — T-02
 * ptm_certification_types: Katalog jenis sertifikasi guru.
 */
class CreatePtmCertificationTypes extends Migration
{
    public function up(): void
    {
        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 10,
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'code' => [
                'type'       => 'VARCHAR',
                'constraint' => 30,
                'null'       => false,
                'comment'    => 'PPG, SERGUR, SERGUR_MADRASAH, GURU_PENGGERAK',
            ],
            'name' => [
                'type'       => 'VARCHAR',
                'constraint' => 150,
                'null'       => false,
            ],
            'issuing_body' => [
                'type'       => 'VARCHAR',
                'constraint' => 100,
                'null'       => true,
                'comment'    => 'Kemendikbudristek, Kemenag',
            ],
            'description' => ['type' => 'TEXT', 'null' => true],
            'is_active'   => ['type' => 'TINYINT', 'constraint' => 1, 'null' => false, 'default' => 1],
            'created_at'  => ['type' => 'DATETIME', 'null' => true],
            'updated_at'  => ['type' => 'DATETIME', 'null' => true],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addUniqueKey('code');
        $this->forge->addKey('is_active');
        $this->forge->createTable('ptm_certification_types', true);

        $this->db->table('ptm_certification_types')->insertBatch([
            ['code' => 'PPG',              'name' => 'PPG Dalam Jabatan',    'issuing_body' => 'Kemendikbudristek', 'is_active' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')],
            ['code' => 'SERGUR',           'name' => 'Sertifikasi Guru',     'issuing_body' => 'Kemendikbudristek', 'is_active' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')],
            ['code' => 'SERGUR_MADRASAH',  'name' => 'Sertifikasi Guru Madrasah', 'issuing_body' => 'Kemenag',    'is_active' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')],
            ['code' => 'GURU_PENGGERAK',   'name' => 'Guru Penggerak',       'issuing_body' => 'Kemendikbudristek', 'is_active' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')],
        ]);
    }

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