<?php

namespace App\Models;

use CodeIgniter\Model;

class AttendanceModel extends Model
{
    protected $table            = 'attendance';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array';
    protected $protectFields    = true;
    protected $allowedFields    = ['user_id', 'date', 'status', 'image_path', 'approval_status', 'remarks'];

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

    public function getPendingAttendance()
    {
        return $this->select('attendance.*, users.name as user_name')
                    ->join('users', 'users.id = attendance.user_id')
                    ->where('attendance.approval_status', 'Pending')
                    ->findAll();
    }

    public function getAllAttendance()
    {
        return $this->select('attendance.*, users.name as user_name')
                    ->join('users', 'users.id = attendance.user_id')
                    ->orderBy('attendance.date', 'DESC')
                    ->findAll();
    }
}
