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

class VendorAd extends BaseModel {
    protected $table = 'vendor_ads';

    public function paginateWithDetails($page = 1, $perPage = 10) {
        $offset = ($page - 1) * $perPage;
        
        $stmt = $this->db->prepare("
            SELECT va.*, v.agency_name, m.full_name as maid_name, ap.name_en as package_name
            FROM {$this->table} va
            LEFT JOIN vendors v ON va.vendor_id = v.id
            LEFT JOIN maids m ON va.maid_id = m.id
            LEFT JOIN ad_packages ap ON va.ad_package_id = ap.id
            ORDER BY va.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
        ];
    }
}
