<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddStatusAndSesiColumns extends Migration
{
    public function up()
    {
        // cek dulu apakah kolom status_karyawan sudah ada
        if (!$this->db->fieldExists('status_karyawan', 'tb_karyawan')) {
            $this->forge->addColumn('tb_karyawan', [
                'status_karyawan' => [
                    'type'       => 'ENUM',
                    'constraint' => ['Aktif', 'Nonaktif'],
                    'default'    => 'Aktif',
                    'null'       => false,
                    'after'      => 'posisi_karyawan',
                ],
            ]);
        }

        // cek dulu apakah kolom sesi sudah ada
        if (!$this->db->fieldExists('sesi', 'tb_absensi')) {
            $this->forge->addColumn('tb_absensi', [
                'sesi' => [
                    'type'  => 'TEXT',
                    'null'  => true,
                    'after' => 'jam_keluar_absensi',
                ],
            ]);
        }
    }

    public function down()
    {
        // hapus jika ada
        if ($this->db->fieldExists('status_karyawan', 'tb_karyawan')) {
            $this->forge->dropColumn('tb_karyawan', 'status_karyawan');
        }

        if ($this->db->fieldExists('sesi', 'tb_absensi')) {
            $this->forge->dropColumn('tb_absensi', 'sesi');
        }
    }
}