import 'package:flutter/material.dart';
import 'package:initial_folder/models/detail_invoice_model.dart';
import 'package:initial_folder/services/detail_invoice_service.dart';
import 'package:provider/provider.dart';

enum ResultState { loading, noData, hasData, error }

class DetailInvoiceProvider extends ChangeNotifier {
  final DetailInvoiceService _detailInvoiceService = DetailInvoiceService();

  List<DataDetailInvoiceModel>? _detailInvoice;
  String? _message;
  String? _thumbnail;
  ResultState? _state;

  String? get message => _message;
  String? get thumbnail => _thumbnail;
  List<DataDetailInvoiceModel>? get detailInvoice => _detailInvoice;
  ResultState? get state => _state;

  set selectedThumbnail(String? value) {
    _thumbnail = value;
    notifyListeners();
  }

  Future<dynamic> fetchDetailInvoice(String? orderId) async {
    try {
      _state = ResultState.loading;
      notifyListeners();
      final data = await _detailInvoiceService.detailInvoice(orderId);
      if (data.isEmpty) {
        _state = ResultState.noData;
        _message = 'Invoice Detail is Empty';
      } else {
        _state = ResultState.hasData;
        _detailInvoice = data;
      }
    } catch (e) {
      _state = ResultState.error;
      _message = 'Error -> $e';
    }
    notifyListeners();
  }
}
