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

class SubscriptionPlan extends BaseModel {
    protected $table = 'subscription_plans';

    public function paginatePlans($page = 1, $perPage = 10) {
        $result = $this->paginate($page, $perPage, [], 'price ASC');
        
        foreach ($result['data'] as &$plan) {
            $stmt = $this->db->prepare("SELECT * FROM subscription_plan_features WHERE plan_id = ? ORDER BY sort_order ASC");
            $stmt->execute([$plan['id']]);
            $features = $stmt->fetchAll();
            
            $plan['features_en'] = [];
            $plan['features_ar'] = [];
            foreach ($features as $f) {
                if (!empty($f['feature_text_en'])) $plan['features_en'][] = $f['feature_text_en'];
                if (!empty($f['feature_text_ar'])) $plan['features_ar'][] = $f['feature_text_ar'];
            }
        }
        
        return $result;
    }
}
