<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateKibTables extends Migration
{
    public function up()
    {
        // Tabel KIB Kategori (Level 1: KIB-A, KIB-B, dst)
        $this->forge->addField([
            'id'        => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'nama_kib'  => ['type' => 'VARCHAR', 'constraint' => 50],   // e.g. KIB-A
            'kode_brg'  => ['type' => 'VARCHAR', 'constraint' => 50],   // e.g. 1.3.1.01.
            'keterangan'=> ['type' => 'TEXT', 'null' => true],
            'created_at'=> ['type' => 'DATETIME', 'null' => true],
            'updated_at'=> ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->createTable('kib_kategori', true);

        // Tabel KIB Detail (Level 2: item barang per KIB)
        $this->forge->addField([
            'id'              => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'id_kib_kategori' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
            'kode'            => ['type' => 'VARCHAR', 'constraint' => 100],  // e.g. 1.3.1.01.01
            'nama_barang'     => ['type' => 'VARCHAR', 'constraint' => 200],
            'keterangan'      => ['type' => 'TEXT', 'null' => true],
            'created_at'      => ['type' => 'DATETIME', 'null' => true],
            'updated_at'      => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->createTable('kib_detail', true);
    }

    public function down()
    {
        $this->forge->dropTable('kib_detail', true);
        $this->forge->dropTable('kib_kategori', true);
    }
}
