register method

Future<ApiResponseModel<DeviceModel?>> register({
  1. required String deviceId,
  2. required DeviceType type,
  3. String? notificationToken,
  4. String? companyId,
})

Registers a new device.

deviceId is the unique device identifier. type is the device type (ANDROID, IOS, WEB). notificationToken is an optional push notification token. companyId is an optional company ID. Returns the created DeviceModel instance.

Implementation

Future<ApiResponseModel<DeviceModel?>> register({
  required String deviceId,
  required DeviceType type,
  String? notificationToken,
  String? companyId,
}) async {
  final url = "$_baseUrl/device/register";

  final payload = {
    'apiKey': _apiKey,
    'deviceId': deviceId,
    'type': type.value,
    if (notificationToken != null) 'notificationToken': notificationToken,
    if (companyId != null) 'companyId': companyId,
  };

  debugPrint("flutter_mon_sms_pro/device/register/payload: $payload");

  final r = await _dio.post(url, data: payload);

  debugPrint("flutter_mon_sms_pro/device/register/data: ${r.data}");

  final response = ApiResponseModel.fromJson(
    r.data,
    (data) => DeviceModel.fromJson(data as Map<String, dynamic>),
  );

  return response;
}