import 'package:equatable/equatable.dart';

/// 用途：WebRTC 信令地址接口响应模型
/// 涉及页面：首页监护舱 - 监控画面
class WebrtcAddressBO extends Equatable {
  /// 错误码
  final int errorCode;

  /// 错误信息
  final String? errorMessage;

  /// 错误提示文案
  final String? errorTips;

  /// SDP 交换 URL 列表（主）
  final List<String> urlList;

  /// SDP 交换 URL 列表（备用）
  final List<String> backupUrlList;

  const WebrtcAddressBO({
    required this.errorCode,
    this.errorMessage,
    this.errorTips,
    required this.urlList,
    required this.backupUrlList,
  });

  factory WebrtcAddressBO.fromJson(Map<String, dynamic> json) {
    final data = json['data'] as Map<String, dynamic>?;
    return WebrtcAddressBO(
      errorCode: json['error_code'] as int? ?? 0,
      errorMessage: json['error_message'] as String?,
      errorTips: json['error_tips'] as String?,
      urlList: _parseStringList(data?['list']),
      backupUrlList: _parseStringList(data?['backup_list']),
    );
  }

  static List<String> _parseStringList(dynamic value) {
    if (value is List) {
      return value.map((e) => e.toString()).toList();
    }
    return [];
  }

  @override
  List<Object?> get props => [errorCode, urlList, backupUrlList];
}
