interaction_models.dart 4.31 KB
class InteractionData {
  const InteractionData({
    required this.friendUserId,
    required this.interactionType,
    required this.actionType,
    this.action,
  });

  /// Target of every V2 action and records request.
  final int friendUserId;
  final int interactionType;
  final int actionType;
  final InteractionDataAction? action;

  factory InteractionData.fromJson(Map<String, dynamic> json) {
    return InteractionData(
      friendUserId: json['friend_user_id'] as int,
      interactionType: json['interaction_type'] as int,
      actionType: json['action_type'] as int,
      action: json['action_variables'] == null
          ? null
          : InteractionDataAction.fromJson(
              json['action_variables'] as Map<String, dynamic>,
            ),
    );
  }

  Map<String, dynamic> toJson() {
    final val = <String, dynamic>{
      'friend_user_id': friendUserId,
      'interaction_type': interactionType,
      'action_type': actionType,
    };
    if (action != null) val['action_variables'] = action!.toJson();
    return val;
  }
}

class InteractionRecordResponse {
  const InteractionRecordResponse({this.records});

  final List<InteractionRecord>? records;

  factory InteractionRecordResponse.fromJson(Map<String, dynamic> json) {
    return InteractionRecordResponse(
      records: (json['records'] as List<dynamic>?)
          ?.map((e) => InteractionRecord.fromJson(e as Map<String, dynamic>))
          .toList(),
    );
  }

  Map<String, dynamic> toJson() {
    final val = <String, dynamic>{};
    if (records != null) {
      val['records'] = records!.map((e) => e.toJson()).toList();
    }
    return val;
  }
}

class InteractionRecord {
  const InteractionRecord({
    this.id,
    this.createTime,
    this.userId,
    this.pairId,
    this.interactionType,
    this.actionType,
    this.action,
    this.text,
  });

  final int? id;
  final int? createTime;
  final int? userId;
  final int? pairId;
  final int? interactionType;
  final int? actionType;
  final InteractionDataAction? action;
  final String? text;

  factory InteractionRecord.fromJson(Map<String, dynamic> json) {
    return InteractionRecord(
      id: json['id'] as int?,
      createTime: json['create_time'] as int?,
      userId: json['user_id'] as int?,
      pairId: json['pair_id'] as int?,
      interactionType: json['interaction_type'] as int?,
      actionType: json['action_type'] as int?,
      action: json['action_variables'] == null
          ? null
          : InteractionDataAction.fromJson(
              json['action_variables'] as Map<String, dynamic>,
            ),
      text: json['text'] as String?,
    );
  }

  Map<String, dynamic> toJson() {
    final val = <String, dynamic>{};
    if (id != null) val['id'] = id;
    if (createTime != null) val['create_time'] = createTime;
    if (userId != null) val['user_id'] = userId;
    if (pairId != null) val['pair_id'] = pairId;
    if (interactionType != null) val['interaction_type'] = interactionType;
    if (actionType != null) val['action_type'] = actionType;
    if (action != null) val['action_variables'] = action!.toJson();
    if (text != null) val['text'] = text;
    return val;
  }
}

class InteractionDataAction {
  const InteractionDataAction({
    this.objectTarget,
    this.status,
    this.type,
    this.date,
    this.value,
    this.unit,
    this.action,
  });

  final int? objectTarget;
  final String? status;
  final String? type;
  final String? date;
  final String? value;
  final String? unit;
  final String? action;

  factory InteractionDataAction.fromJson(Map<String, dynamic> json) {
    return InteractionDataAction(
      objectTarget: json['object'] as int?,
      status: json['data_status'] as String?,
      type: json['data_type'] as String?,
      date: json['data_date'] as String?,
      value: json['data_value'] as String?,
      unit: json['data_unit'] as String?,
      action: json['action'] as String?,
    );
  }

  Map<String, dynamic> toJson() {
    final val = <String, dynamic>{};
    if (objectTarget != null) val['object'] = objectTarget;
    if (status != null) val['data_status'] = status;
    if (type != null) val['data_type'] = type;
    if (date != null) val['data_date'] = date;
    if (value != null) val['data_value'] = value;
    if (unit != null) val['data_unit'] = unit;
    if (action != null) val['action'] = action;
    return val;
  }
}