import 'wayz_common_models.dart';

/// IP location response.
class WzIpLocationResponse {
  /// Success fields
  final String? country;
  final String? province;
  final String? city;
  final String? district;
  final String? center;
  final String? reliability;

  /// Failure fields
  final String? message;

  WzIpLocationResponse({
    this.country,
    this.province,
    this.city,
    this.district,
    this.center,
    this.reliability,
    this.message,
  });

  factory WzIpLocationResponse.fromJson(Map<String, dynamic> json) {
    return WzIpLocationResponse(
      country: WzJson.toStringOrNull(json['country']),
      province: WzJson.toStringOrNull(json['province']),
      city: WzJson.toStringOrNull(json['city']),
      district: WzJson.toStringOrNull(json['district']),
      center: WzJson.toStringOrNull(json['center']),
      reliability: WzJson.toStringOrNull(json['reliability']),
      message: WzJson.toStringOrNull(json['message']),
    );
  }

  Map<String, dynamic> toJson() {
    final out = <String, dynamic>{};
    if (country != null) out['country'] = country;
    if (province != null) out['province'] = province;
    if (city != null) out['city'] = city;
    if (district != null) out['district'] = district;
    if (center != null) out['center'] = center;
    if (reliability != null) out['reliability'] = reliability;
    if (message != null) out['message'] = message;
    return out;
  }
}

