import 'dart:io';

import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:logging/logging.dart';
import 'package:uuid/uuid.dart';

final log = Logger('firebaseHelper');

final FirebaseAuth auth = FirebaseAuth.instance;

Future<String> getToken() async {
  FirebaseUser firebaseUser = await auth.currentUser();
  IdTokenResult token = await firebaseUser.getIdToken();
  return token.token;
}

Future<String> uploadStorage(String path, File file, {String fileName}) async {
  if (fileName == null) {
    fileName = Uuid().v4();
  }
  StorageReference storageReference =
      FirebaseStorage.instance.ref().child('$path/$fileName');
  StorageUploadTask uploadTask = storageReference.putFile(file);
  await uploadTask.onComplete;
  String downloadUrl = await storageReference.getDownloadURL();
  print("name:${await storageReference.getName()}");
  print("bucket:${await storageReference.getBucket()}");
  print("path:${await storageReference.getPath()}");
  print("meta:${await storageReference.getMetadata()}");
  return downloadUrl;
}
