class LoginModel {
  final String accessToken;
  final String refreshToken;
  final int refreshMaxAge;
  final PartnerModel partner;

  const LoginModel({
    required this.accessToken,
    required this.refreshToken,
    required this.refreshMaxAge,
    required this.partner,
  });

  factory LoginModel.fromJson(Map<String, dynamic> json) {
    // Debug logs (remove in production)
    // print("ACCESS TOKEN: ${json['accessToken']}");
    // print("REFRESH TOKEN: ${json['partner_refresh_token']}");

    return LoginModel(
      accessToken: json['accessToken'] ?? '',
      refreshToken: json['partner_refresh_token'] ?? '', // ✅ fixed key
      refreshMaxAge: json['refreshMaxAge'] ?? 0, // may not come from API
      partner: json['partner'] != null
          ? PartnerModel.fromJson(json['partner'])
          : const PartnerModel(
        id: 0,
        email: '',
        name: '',
        roleXid: 0,
      ),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'accessToken': accessToken,
      'partner_refresh_token': refreshToken, // ✅ match API
      'refreshMaxAge': refreshMaxAge,
      'partner': partner.toJson(),
    };
  }
}

class PartnerModel {
  final int id;
  final String email;
  final String name;
  final int roleXid;

  const PartnerModel({
    required this.id,
    required this.email,
    required this.name,
    required this.roleXid,
  });

  factory PartnerModel.fromJson(Map<String, dynamic> json) {
    return PartnerModel(
      id: json['id'] ?? 0,
      email: json['email'] ?? '',
      name: json['name'] ?? '',
      roleXid: json['roleXid'] ?? 0,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'email': email,
      'name': name,
      'roleXid': roleXid,
    };
  }
}