<?php
namespace App\Models;

use CodeIgniter\Model;

class UserModel extends Model
{
    protected $table      = 'usuarios';
    protected $primaryKey = 'id_usuario';
    protected $allowedFields = ['username', 'password', 'email', 'id_rol'];
    protected $returnType    = 'array';
    protected $useTimestamps = false;

    public function getUsersWithRole()
    {
        return $this->select('usuarios.*, roles.nombre_rol')
                    ->join('roles', 'roles.id_rol = usuarios.id_rol')
                    ->orderBy('usuarios.id_usuario', 'DESC')
                    ->findAll();
    }

    public function getUserByUsername($username)
    {
        return $this->where('username', $username)->first();
    }
}
