<?php
require_once __DIR__ . '/BaseModel.php';

class Maid extends BaseModel {
    protected $table = 'maids';

    public function getTotalAvailableCount() {
        $stmt = $this->db->query("SELECT COUNT(*) FROM {$this->table} WHERE availability_status = 'available'");
        return $stmt->fetchColumn();
    }

    public function paginateWithDetails($page = 1, $perPage = 10) {
        $offset = ($page - 1) * $perPage;
        
        $stmt = $this->db->prepare("
            SELECT m.*, v.agency_name, n.name_en as nationality_en, n.name_ar as nationality_ar
            FROM {$this->table} m
            LEFT JOIN vendors v ON m.vendor_id = v.id
            LEFT JOIN nationalities n ON m.nationality_id = n.id
            ORDER BY m.id DESC LIMIT ? OFFSET ?
        ");
        $stmt->bindValue(1, $perPage, PDO::PARAM_INT);
        $stmt->bindValue(2, $offset, PDO::PARAM_INT);
        $stmt->execute();
        $data = $stmt->fetchAll();
        
        $countStmt = $this->db->query("SELECT COUNT(*) FROM {$this->table}");
        $total = $countStmt->fetchColumn();
        
        return [
            'data' => $data,
            'total' => $total,
            'page' => $page,
            'per_page' => $perPage
        ];
    }
}
