import 'dart:convert';

import 'package:jwt_decoder/jwt_decoder.dart';
import 'package:secure_string_operations/secure_string_operations.dart';
import 'package:siro_service/controller/functions/crud.dart';

import '../../constant/box_name.dart';
import '../../constant/char_map.dart';
import '../../constant/info.dart';
import '../../constant/links.dart';
import '../../env/env.dart';
import '../../main.dart';
import '../../print.dart';

class AppInitializer {
  List<Map<String, dynamic>> links = [];

  // Future<void> initializeApp() async {
  //   if (box.read(BoxName.jwt) == null) {
  //     await CRUD().getJWT();
  //   } else {
  //     bool isTokenExpired = JwtDecoder.isExpired(X
  //         .r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs)
  //         .toString()
  //         .split(AppInformation.addd)[0]);
  //     if (isTokenExpired) {
  //       await CRUD().getJWT();
  //     }
  //   }
  // }

  getAIKey(String key1) async {
    if (box.read(BoxName.firstTimeLoadKey) == null) {
      var res =
          await CRUD().get(link: Env.getapiKey, payload: {"keyName": key1});
      if (res != 'failure') {
        var d = res['message'];
        await storage.write(key: key1, value: d[key1].toString());
        await Future.delayed(Duration.zero);
      } else {}
    }
  }
}
