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

class VendorDocument extends BaseModel {
    protected $table = 'vendor_documents';

    public function paginateWithDetails($page = 1, $perPage = 10) {
        $offset = ($page - 1) * $perPage;
        
        $stmt = $this->db->prepare("
            SELECT vd.*, v.agency_name, dt.name_en as document_type_name
            FROM {$this->table} vd
            LEFT JOIN vendors v ON vd.vendor_id = v.id
            LEFT JOIN document_types dt ON vd.document_type_id = dt.id
            ORDER BY vd.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
        ];
    }
}
