import '../../marianumconnect_query.dart';

/// Registers (upserts) this device's push subscription with MarianumConnect via
/// `PUT /api/mobile/v1/me/push-device`. The backend verifies the Nextcloud
/// device-identifier signature, stores the routing metadata and starts
/// forwarding Nextcloud pushes to this device's FCM token. Responds 204.
class PushDeviceRegister extends MarianumConnectQuery {
  PushDeviceRegister({super.dio});

  Future<void> run({
    required String deviceIdentifier,
    required String deviceIdentifierSignature,
    required String userPublicKey,
    required String pushToken,
    required String platform,
    required String registrationType,
    String? appVersion,
  }) => guard(() async {
    await dio.put<void>(
      endpoint('me/push-device'),
      data: {
        'deviceIdentifier': deviceIdentifier,
        'deviceIdentifierSignature': deviceIdentifierSignature,
        'userPublicKey': userPublicKey,
        'pushToken': pushToken,
        'platform': platform,
        // 'general' | 'talk' — the backend derives the NC hash comparison
        // value from it (general = sha512(token), talk = sha512(token+'#talk')).
        'registrationType': registrationType,
        'appVersion': ?appVersion,
      },
    );
  });
}
