import 'package:IQ/app/global/converted_bytes.dart';
import 'package:IQ/app/modules/home/models/traffic_model.dart';
import 'dart:convert';

import 'package:IQ/app/global/snono_encrypt.dart';
import 'package:IQ/app/modules/service/api_service.dart';

String? totalGBs;
bool getTodayTrafficLoads = false;

getTodayTraffic() async {
  String payload = AES.encrypt(
    data: jsonEncode({
      "report_type": "daily",
      "month": DateTime.now().month,
      "year": DateTime.now().year,
      "user_id": null,
    }),
    passpharse: 'abcdefghijuklmno0123456789012345',
  );
  var value = await APIService.post('traffic', payload);

  Traffic responseData = Traffic.fromJson(jsonDecode(value));
  String totalGBsNums = formatBytes(
    (responseData.data?.totalReal?[DateTime.now().day - 1]) ?? 0,
    0,
  ).split(' ')[0];
  String totalGBsStrs = formatBytes(
    (responseData.data?.totalReal?[DateTime.now().day - 1]) ?? 0,
    0,
  ).split(' ')[1];

  totalGBs =
          // defaultLocale != "en"
          //     ?
          '$totalGBsNums $totalGBsStrs'
      // : '$totalGBsStrs $totalGBsNums'
      ;
  // totalGBs = 0;
  getTodayTrafficLoads = true;
}
