<?php

namespace App\Models;

use CodeIgniter\Model;

class KaryawanModel extends Model
{
    protected $table            = 'tb_karyawan';
    protected $primaryKey       = 'id_karyawan';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array';

    protected $allowedFields    = [
        'nama_karyawan',
        'posisi_karyawan',
        'rate_gaji_per_jam_karyawan',
        'status_karyawan',
    ];

    protected $useTimestamps = false; // created_at dihandle DEFAULT CURRENT_TIMESTAMP di DB

    public function toggleStatusKaryawan($id)
    {
        $karyawan = $this->find($id);
        if (! $karyawan) {
            return false;
        }
        
        $newStatus = $karyawan['status_karyawan'] === 'Aktif' ? 'Non-Aktif' : 'Aktif';
        return $this->update($id, ['status_karyawan' => $newStatus]);
    }
}