import 'dart:math';

import 'package:flutter_test/flutter_test.dart';
import 'package:tane/services/device_id_store.dart';

import '../support/test_support.dart';

void main() {
  test('generates a 64-bit hex id and persists it', () async {
    final secret = InMemorySecretStore();
    final id = await DeviceIdStore(secret).deviceId();
    expect(id, matches(RegExp(r'^[0-9a-f]{16}$')));

    // A fresh store over the same keystore reads the SAME id (stable install).
    final again = await DeviceIdStore(secret).deviceId();
    expect(again, id);
  });

  test('is stable across calls on one instance', () async {
    final store = DeviceIdStore(InMemorySecretStore());
    expect(await store.deviceId(), await store.deviceId());
  });

  test('two fresh installs get different ids', () async {
    final a = await DeviceIdStore(InMemorySecretStore(), random: Random(1))
        .deviceId();
    final b = await DeviceIdStore(InMemorySecretStore(), random: Random(2))
        .deviceId();
    expect(a, isNot(b));
  });
}
