import 'package:json_annotation/json_annotation.dart';

/// Created by Haoyi on 6/3/21

part 'user.g.dart';

@Deprecated("Use Guru User instead")
typedef SaasUser = GuruUser;

@JsonSerializable()
class GuruUser {
  @JsonKey(name: 'uid', defaultValue: "")
  final String uid;

  @JsonKey(name: 'token', defaultValue: "")
  final String token;

  @JsonKey(name: 'firebaseToken', defaultValue: "")
  final String firebaseToken;

  @JsonKey(name: 'createdAtTimestamp', defaultValue: 0)
  final int createAtTimestamp;

  // bool get isAnonymous => (type == null) || (type == LOGIN_WITH_ANONYMOUS);

  bool get isValid =>
      (uid != "") && (token.isNotEmpty == true) && (firebaseToken.isNotEmpty == true);

  GuruUser(
      {required this.uid,
      required this.token,
      required this.firebaseToken,
      this.createAtTimestamp = 0});

  factory GuruUser.fromJson(Map<String, dynamic> json) => _$GuruUserFromJson(json);

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

  GuruUser copyWith({String? firebaseToken, String? token}) {
    return GuruUser(
        uid: uid, token: token ?? this.token, firebaseToken: firebaseToken ?? this.firebaseToken);
  }

  bool isSame(GuruUser? user) {
    return uid == user?.uid &&
        token == user?.token &&
        firebaseToken == user?.firebaseToken &&
        createAtTimestamp == user?.createAtTimestamp;
  }

  @override
  String toString() {
    return 'SaasUser{uid: $uid, token: $token, firebaseToken: $firebaseToken, createAtTimestamp: $createAtTimestamp}';
  }
}

// 匿名登录请求数据
@JsonSerializable()
class AnonymousLoginReqBody {
  @JsonKey(name: 'secret', defaultValue: "")
  final String secret;

  AnonymousLoginReqBody({required this.secret});

  // @override
  // String toString() {
  //   return "{secret: '$secret'}";
  // }

  factory AnonymousLoginReqBody.fromJson(Map<String, dynamic> json) =>
      _$AnonymousLoginReqBodyFromJson(json);

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

@JsonSerializable()
class FacebookLoginReqBody {
  @JsonKey(name: 'accessToken', defaultValue: "")
  final String? accessToken;

  FacebookLoginReqBody({this.accessToken});

  @override
  String toString() {
    return 'FacebookLoginReqBody{accessToken: $accessToken}';
  }

  factory FacebookLoginReqBody.fromJson(Map<String, dynamic> json) =>
      _$FacebookLoginReqBodyFromJson(json);

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

@JsonSerializable()
class GoogleLoginReqBody {
  @JsonKey(name: 'idToken', defaultValue: "")
  final String? idToken;

  GoogleLoginReqBody({this.idToken});

  @override
  String toString() {
    return 'GoogleLoginReqBody{idToken: $idToken}';
  }

  factory GoogleLoginReqBody.fromJson(Map<String, dynamic> json) =>
      _$GoogleLoginReqBodyFromJson(json);

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

@JsonSerializable()
class AppleLoginReqBody {
  @JsonKey(name: 'token', defaultValue: "")
  final String? token;

  @JsonKey(name: 'clientType', defaultValue: "ios")
  final String clientType;

  AppleLoginReqBody({this.token, this.clientType = "ios"});

  @override
  String toString() {
    return 'AppleLoginReqBody{token: $token, clientType: $clientType}';
  }

  factory AppleLoginReqBody.fromJson(Map<String, dynamic> json) =>
      _$AppleLoginReqBodyFromJson(json);

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

@JsonSerializable()
class FirebaseTokenData {
  @JsonKey(name: 'uid', defaultValue: "")
  final String uid;

  @JsonKey(name: 'firebaseToken', defaultValue: "")
  final String firebaseToken;

  FirebaseTokenData({this.uid = "", this.firebaseToken = ""});

  factory FirebaseTokenData.fromJson(Map<String, dynamic> json) =>
      _$FirebaseTokenDataFromJson(json);

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

  @override
  String toString() {
    return 'FirebaseTokenData{uid: $uid, firebaseToken: $firebaseToken}';
  }
}

@JsonSerializable()
class UserAuthInfo {
  @JsonKey(name: "secret", defaultValue: "")
  final String secret;

  @JsonKey(name: 'providerList', defaultValue: const <String>[])
  final List<String> providerList;

  factory UserAuthInfo.fromJson(Map<String, dynamic> json) => _$UserAuthInfoFromJson(json);

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

  UserAuthInfo({this.secret = "", this.providerList = const []});

  @override
  String toString() {
    return 'UserAuthList{providerList: $providerList}';
  }
}

@JsonSerializable()
class UnbindReqBody {
  @JsonKey(name: 'provider', defaultValue: "")
  final String provider;

  UnbindReqBody({this.provider = ""});

  @override
  String toString() {
    return 'UnbindReqBody{provider: $provider}';
  }

  factory UnbindReqBody.fromJson(Map<String, dynamic> json) => _$UnbindReqBodyFromJson(json);

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

class UserAttr {
  static const real = 0;
  static const tester = 10;
  static const machine = 100;
}
