import 'package:uuid/uuid.dart';

import 'package:logging/logging.dart';

import 'package:pshared/config/constants.dart';
import 'package:pshared/service/secure_storage.dart';

class DeviceIdManager {
  static final _logger = Logger('service.device_id');

  static final String _key = Constants.deviceIdStorageKey;
  static Future<String> getDeviceId() async {
    String? deviceId = await SecureStorageService.get(_key);

    if (deviceId == null) {
      _logger.fine('Device id is not set, generating new');
      deviceId = (const Uuid()).v4();
      await SecureStorageService.set(_key, deviceId);
    }

    return deviceId;
  }
}
