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

class VendorSubscription extends BaseModel {
    protected $table = 'vendor_subscriptions';

    public function paginateWithDetails($page = 1, $perPage = 10) {
        $offset = ($page - 1) * $perPage;
        
        $stmt = $this->db->prepare("
            SELECT vs.*, v.agency_name, sp.name_en as plan_name, sp.price, sp.currency
            FROM {$this->table} vs
            LEFT JOIN vendors v ON vs.vendor_id = v.id
            LEFT JOIN subscription_plans sp ON vs.plan_id = sp.id
            ORDER BY vs.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
        ];
    }
}
