import 'package:json_annotation/json_annotation.dart';

part 'user_info.g.dart';

@JsonSerializable()
class UserInfo extends Object {
  @JsonKey(name: 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier')
  String nameidentifier;

  @JsonKey(name: 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname')
  String givenname;

  @JsonKey(name: 'is_admin')
  String isAdmin;

  @JsonKey(name: 'term_year')
  String termYear;

  @JsonKey(name: 'nbf')
  int nbf;

  @JsonKey(name: 'exp')
  int exp;

  @JsonKey(name: 'iss')
  String iss;

  @JsonKey(name: 'aud')
  String aud;

  UserInfo(
    this.nameidentifier,
    this.givenname,
    this.isAdmin,
    this.termYear,
    this.nbf,
    this.exp,
    this.iss,
    this.aud,
  );

  factory UserInfo.fromJson(Map<String, dynamic> srcJson) => _$UserInfoFromJson(srcJson);

  Map<String, dynamic> toJson() => _$UserInfoToJson(this);

  bool isExpired() {
    int millisecondsSinceEpoch = DateTime.now().millisecondsSinceEpoch;
    return millisecondsSinceEpoch >= exp;
  }
}
