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

class Notification extends BaseModel {
    protected $table = 'notifications';

    public function paginateWithDetails($page = 1, $perPage = 10) {
        $offset = ($page - 1) * $perPage;
        
        $stmt = $this->db->prepare("
            SELECT n.*, 
                   IF(n.receiver_type = 'customer', c.full_name, IF(n.receiver_type = 'vendor', v.agency_name, 'Admin')) as receiver_name
            FROM {$this->table} n
            LEFT JOIN customers c ON n.receiver_type = 'customer' AND n.receiver_id = c.id
            LEFT JOIN vendors v ON n.receiver_type = 'vendor' AND n.receiver_id = v.id
            ORDER BY n.created_at 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
        ];
    }
}
