import 'package:flutter/foundation.dart';

import 'package:pshared/provider/payment/multiple/quotation.dart';


class MultiQuotationController extends ChangeNotifier {
  MultiQuotationProvider? _quotation;

  void update(MultiQuotationProvider quotation) {
    if (identical(_quotation, quotation)) return;
    _quotation?.removeListener(_handleQuotationChanged);
    _quotation = quotation;
    _quotation?.addListener(_handleQuotationChanged);
    _handleQuotationChanged();
  }

  bool get isLoading => _quotation?.isLoading ?? false;
  Exception? get error => _quotation?.error;
  bool get canRefresh => _quotation?.canRefresh ?? false;
  bool get isReady => _quotation?.isReady ?? false;

  DateTime? get quoteExpiresAt => _quotation?.quoteExpiresAt;

  void refreshQuotation() {
    _quotation?.refreshQuotation();
  }

  void _handleQuotationChanged() {
    notifyListeners();
  }

  @override
  void dispose() {
    _quotation?.removeListener(_handleQuotationChanged);
    super.dispose();
  }
}
