/// 加密訊息 DTO
/// 負責與原生平台傳輸加密資料
library;

import '../../domain/entities/encrypted_message.dart';

class EncryptedMessageDto {
  final int round;
  final String data;

  const EncryptedMessageDto({
    required this.round,
    required this.data,
  });

  /// 從標準化響應創建
  /// 響應格式: {"success": true, "data": {"round": int, "encryptedData": "..."}, "error": null}
  factory EncryptedMessageDto.fromResponse(Map<String, dynamic> response) {
    final data = response['data'] as Map<String, dynamic>? ?? {};

    return EncryptedMessageDto(
      round: data['round'] as int? ?? 0,
      data: data['encryptedData']?.toString() ?? '',
    );
  }

  /// 轉換為 JSON
  Map<String, dynamic> toJson() {
    return {
      'round': round,
      'data': data,
    };
  }

  /// 轉換為 Domain Entity
  EncryptedMessage toEntity() {
    return EncryptedMessage(
      round: round,
      data: data,
    );
  }

  /// 從 Domain Entity 創建
  static EncryptedMessageDto fromEntity(EncryptedMessage entity) {
    return EncryptedMessageDto(
      round: entity.round,
      data: entity.data,
    );
  }
}

