import 'package:azlistview/azlistview.dart';
import 'package:lpinyin/lpinyin.dart';

class TeamUserEntity {
  int pageNum;
  int pageCount;
  int total;
  int pageSize;
  bool hasNext;
  bool hasPrev;
  List<UserItem> rows;

  TeamUserEntity(
      {this.pageNum,
        this.pageCount,
        this.total,
        this.pageSize,
        this.hasNext,
        this.hasPrev,
        this.rows});

  TeamUserEntity.fromJsonMap(Map<String, dynamic> json) {
    pageNum = json['pageNum'];
    pageCount = json['pageCount'];
    total = json['total'];
    pageSize = json['pageSize'];
    hasNext = json['hasNext'];
    hasPrev = json['hasPrev'];
    if (json['rows'] != null) {
      rows = new List<UserItem>();
      json['rows'].forEach((v) {
        rows.add(new UserItem.fromJsonMap(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['pageNum'] = pageNum;
    data['pageCount'] = pageCount;
    data['total'] = total;
    data['pageSize'] = pageSize;
    data['hasNext'] = hasNext;
    data['hasPrev'] = hasPrev;
    data['rows'] =
        rows != null ? this.rows.map((v) => v.toJson()).toList() : null;
    return data;
  }
}

class UserItem extends ISuspensionBean {
  String userId;
  String userName;
  String userAvatarUrl;
  String userRemarks;
  String userMobile;
  String userRoleId;
  String userRoleName;
  LiftCertificate liftCertificate;

  UserItem.fromJsonMap(Map<String, dynamic> map)
      : userId = map["userId"]??"",
        userName = map["userName"]??"",
        userAvatarUrl = map["userAvatarUrl"]??"",
        userRemarks = map["userRemarks"]??"",
        userMobile = map["userMobile"]??"",
        userRoleId = map["userRoleId"]??"",
        userRoleName = map["userRoleName"]??"",
        liftCertificate = map['liftCertificate'] != null
            ? new LiftCertificate.fromJsonMap(map['liftCertificate'])
            : null;

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['userId'] = userId;
    data['userName'] = userName;
    data['userAvatarUrl'] = userAvatarUrl;
    data['userRemarks'] = userRemarks;
    data['userMobile'] = userMobile;
    data['userRoleId'] = userRoleId;
    data['userRoleName'] = userRoleName;
    data['liftCertificate'] =
        liftCertificate == null ? null : liftCertificate.toJson();
    return data;
  }

  @override
  String getSuspensionTag() {
    String py = PinyinHelper.getShortPinyin(userName).toUpperCase();
    return py.substring(0, 1);
  }
}

class LiftCertificate {
  String userId;
  String code;
  String issuanceAgency;
  String expirationDate;
  String certificateType;
  String firstImgUrl;
  String secondImgUrl;
  int status;

  LiftCertificate.fromJsonMap(Map<String, dynamic> map)
      : userId = map["userId"]??"",
        code = map["code"]??"",
        issuanceAgency = map["issuanceAgency"]??"",
        expirationDate = map["expirationDate"]??"",
        certificateType = map["certificateType"]??"",
        firstImgUrl = map["firstImgUrl"]??"",
        secondImgUrl = map["secondImgUrl"]??"",
        status = map["status"]??0;

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['userId'] = userId;
    data['code'] = code;
    data['issuanceAgency'] = issuanceAgency;
    data['expirationDate'] = expirationDate;
    data['certificateType'] = certificateType;
    data['firstImgUrl'] = firstImgUrl;
    data['secondImgUrl'] = secondImgUrl;
    data['status'] = status;
    return data;
  }
}
