import 'dart:convert';

import 'package:firebase_database/firebase_database.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../model/subscription_plan_model.dart';

final subscriptionPlansProvider = FutureProvider<List<SubscriptionPlanModel>>((ref) async {
  final snapshot = await FirebaseDatabase.instance
      .ref()
      .child('Admin Panel')
      .child('Subscription Plan')
      .orderByKey()
      .get();

  final List<SubscriptionPlanModel> plans = [];
  print('sadsadsa: $snapshot');

  for (var element in snapshot.children) {
    print('element: $element');
    final plan = SubscriptionPlanModel.fromJson(
      jsonDecode(jsonEncode(element.value)),
    );
    plans.add(plan);
  }

  return plans;
});
