
import 'package:flutter/cupertino.dart';
import 'package:generp/Models/hrmModels/attendanceRequestDetailsResponse.dart';
import 'package:provider/provider.dart';

import '../../Models/hrmModels/attendanceRequestListResponse.dart';
import '../../services/api_calling.dart';
import '../HomeScreenNotifier.dart';


class AttendanceDetailsProvider extends ChangeNotifier {
  attendanceRequestDetailsResponse? _response;
  bool _isLoading = false;
  String? _errorMessage;

  attendanceRequestDetailsResponse? get response => _response;
  bool get isLoading => _isLoading;
  String? get errorMessage => _errorMessage;

  Future<void> fetchAttendanceRequestDetail(context,String requestId) async {
    _isLoading = true;
    _errorMessage = null;
    _response = null;
    notifyListeners();

    try {
      final provider = Provider.of<HomescreenNotifier>(context, listen: false);
      final result = await ApiCalling.attendanceRequestDetailAPI(provider.empId, provider.session, requestId);

      if (result != null) {
        _response = result;
      } else {
        _errorMessage = "No data found!";
      }
    } catch (e) {
      _errorMessage = "Something went wrong: $e";
    }

    _isLoading = false;
    notifyListeners();
  }
}
