
import 'dart:convert';

class User {
  int? id;
  String? username;
  String? nickname;
  String? mobile;
  String? email;
  String? avatarUrl;
  int? lastAddressId;
  String? passCode;
  double? credit;
  double? wallet;
  int? coupon;
  int? points;
  int? orderNum;
  double? pointsToCreditsConversionRate;
  String? contactNumber;
  String? flutterMiniStoreToken;

  User.fromJson(Map<String, dynamic> json)
      : id = json['id'],
        username = json['username'],
        nickname = json['nickname'],
        mobile = json['mobile'],
        email = json['email'],
        avatarUrl = json['avatar_url'],
        lastAddressId = json['last_address_id'],
        passCode = json['pass_code'],
        credit = double.parse(json['credit'].toString()),
        wallet = double.parse((json['wallet'] == null) ? "0": json['wallet'].toString()),
        coupon = json['coupon'],
        points = json['points'],
        orderNum = json['order_num'],
        pointsToCreditsConversionRate = double.parse(json['points_to_credits_conversion_rate'].toString()),
        contactNumber = json['contact_number'],
        flutterMiniStoreToken = json['flutter_ministore_token'];

  Map<String, dynamic> toJson() => {
    'id': id,
    'username': username,
    'nickname': nickname,
    'mobile': mobile,
    'email': email,
    'avatar_url': avatarUrl,
    'last_address_id': lastAddressId,
    'pass_code': passCode,
    'credit': credit,
    'wallet': wallet,
    'coupon': coupon,
    'points': points,
    'order_num': orderNum,
    'points_to_credits_conversion_rate': pointsToCreditsConversionRate,
    'contact_number': contactNumber,
    'flutter_ministore_token': flutterMiniStoreToken,
  };

  @override
  String toString() {
    return json.encode(this);
  }
}