<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateStudentsTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id'              => ['type' => 'BIGINT', 'unsigned' => true, 'auto_increment' => true],
            // Identitas
            'nis'             => ['type' => 'VARCHAR', 'constraint' => 20],
            'nisn'            => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true],
            'nik'             => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true],
            'full_name'       => ['type' => 'VARCHAR', 'constraint' => 100],
            'gender'          => ['type' => 'ENUM', 'constraint' => ['L', 'P']],
            'birth_place'     => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
            'birth_date'      => ['type' => 'DATE', 'null' => true],
            'religion'        => ['type' => 'ENUM', 'constraint' => ['Islam', 'Kristen', 'Katolik', 'Hindu', 'Buddha', 'Konghucu'], 'default' => 'Islam'],
            'photo'           => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
            // Akademik
            'entry_year'      => ['type' => 'YEAR', 'null' => true],
            'entry_date'      => ['type' => 'DATE', 'null' => true],
            'origin_school'   => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true],
            'status'          => ['type' => 'ENUM', 'constraint' => ['Aktif', 'Alumni', 'Mutasi', 'Drop Out'], 'default' => 'Aktif'],
            // Alamat
            'address'         => ['type' => 'TEXT', 'null' => true],
            'rt'              => ['type' => 'VARCHAR', 'constraint' => 5, 'null' => true],
            'rw'              => ['type' => 'VARCHAR', 'constraint' => 5, 'null' => true],
            'village'         => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
            'district'        => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
            'city'            => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
            'province'        => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
            'postal_code'     => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
            'phone'           => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true],
            // Ayah
            'father_name'     => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
            'father_nik'      => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true],
            'father_birth'    => ['type' => 'DATE', 'null' => true],
            'father_edu'      => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true],
            'father_job'      => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
            'father_phone'    => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true],
            // Ibu
            'mother_name'     => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
            'mother_nik'      => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true],
            'mother_birth'    => ['type' => 'DATE', 'null' => true],
            'mother_edu'      => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true],
            'mother_job'      => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
            'mother_phone'    => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true],
            // Timestamps
            'created_at'      => ['type' => 'DATETIME', 'null' => true],
            'updated_at'      => ['type' => 'DATETIME', 'null' => true],
            'deleted_at'      => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addPrimaryKey('id');
        $this->forge->addUniqueKey('nis');
        $this->forge->createTable('students');
    }

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