class LoginResponse {
  const LoginResponse({
    required this.success,
    this.accessToken,
    this.tokenType,
    this.expiresIn,
    this.username,
    this.roles = const [],
    this.message,
  });

  factory LoginResponse.fromJson(Map<String, dynamic> json) {
    return LoginResponse(
      success: json['success'] == true,
      accessToken: json['accessToken'] as String?,
      tokenType: json['tokenType'] as String?,
      expiresIn: (json['expiresIn'] as num?)?.toInt(),
      username: json['username'] as String?,
      roles: (json['roles'] as List<dynamic>?)
              ?.map((role) => role.toString())
              .toList() ??
          const [],
      message: json['message'] as String?,
    );
  }

  final bool success;
  final String? accessToken;
  final String? tokenType;
  final int? expiresIn;
  final String? username;
  final List<String> roles;
  final String? message;

  LoginResponse copyWith({
    bool? success,
    String? accessToken,
    String? tokenType,
    int? expiresIn,
    String? username,
    List<String>? roles,
    String? message,
  }) {
    return LoginResponse(
      success: success ?? this.success,
      accessToken: accessToken ?? this.accessToken,
      tokenType: tokenType ?? this.tokenType,
      expiresIn: expiresIn ?? this.expiresIn,
      username: username ?? this.username,
      roles: roles ?? this.roles,
      message: message ?? this.message,
    );
  }
}