/// RSA 金鑰對 DTO
/// 負責與原生平台傳輸資料
library;

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

class RsaKeyPairDto {
  final String publicKey;
  final String privateKey;

  const RsaKeyPairDto({
    required this.publicKey,
    required this.privateKey,
  });

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

    return RsaKeyPairDto(
      publicKey: data['publicKey']?.toString() ?? '',
      privateKey: data['privateKey']?.toString() ?? '',
    );
  }

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

  /// 轉換為 Domain Entity
  RsaKeyPair toEntity() {
    return RsaKeyPair(
      publicKey: publicKey,
      privateKey: privateKey,
    );
  }

  /// 從 Domain Entity 創建
  static RsaKeyPairDto fromEntity(RsaKeyPair entity) {
    return RsaKeyPairDto(
      publicKey: entity.publicKey,
      privateKey: entity.privateKey,
    );
  }
}

