<?php

namespace App\Models;

use CodeIgniter\Model;

class UserModel extends Model
{
    protected $table      = 'users';
    protected $primaryKey = 'id';
    protected $returnType = 'array';

    protected $allowedFields = ['nama', 'username', 'password', 'role', 'is_active'];

    protected $useTimestamps = true;
    protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';

    public function findByUsername(string $username): ?array
    {
        return $this->where('username', $username)->first();
    }

    public function getAll(): array
    {
        return $this->orderBy('id', 'ASC')->findAll();
    }
}
