import 'package:flutter/material.dart';
import 'package:hub/features/backend/index.dart';
import 'package:hub/features/history/index.dart';
import 'package:hub/features/storage/index.dart';
import 'package:hub/flutter_flow/flutter_flow_model.dart';
import 'package:hub/flutter_flow/request_manager.dart';

class AcessHistoryPageModel extends FlutterFlowModel<AccessHistoryScreen> {
  late final String devUUID;
  late final String userUUID;
  late final String cliUUID;

  final unfocusNode = FocusNode();
  final _accessHistoryManager = FutureRequestManager<ApiCallResponse>();
  Future<ApiCallResponse> accessHistory({
    String? uniqueQueryKey,
    bool? overrideCache,
    required Future<ApiCallResponse> Function() requestFn,
  }) =>
      _accessHistoryManager.performRequest(
        uniqueQueryKey: uniqueQueryKey,
        overrideCache: overrideCache,
        requestFn: requestFn,
      );
  void clearAccessHistoryCache() => _accessHistoryManager.clear();
  void clearAccessHistoryCacheKey(String? uniqueKey) =>
      _accessHistoryManager.clearRequest(uniqueKey);

  @override
  void initState(BuildContext context) {
    initDatabase();
  }

  Future<void> initDatabase() async {
    devUUID = (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    cliUUID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
  }

  @override
  void dispose() {
    unfocusNode.dispose();

    clearAccessHistoryCache();
  }
}
