import 'package:legacy_shared/legacy_shared.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'get_app_users_response_model.freezed.dart';
part 'get_app_users_response_model.g.dart';

@freezed
abstract class GetAppUsersResponseModel with _$GetAppUsersResponseModel {
  const factory GetAppUsersResponseModel({
    required List<GetAppUsersItemResponseModel> items,
  }) = _GetAppUsersResponseModel;

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

}

@freezed
abstract class GetAppUsersItemResponseModel with _$GetAppUsersItemResponseModel {
  const factory GetAppUsersItemResponseModel({
    required String id,
    required String delegationId,
    required String email,
    required String createdAt,
    required String updatedAt,
    required String status,
    required String role,
    required String lastLogin,
    required String currentLogin,
    required String language,
    required String firstName,
    required String lastName,
    required String hasApiKey,
    required String phone
  }) =
  _GetAppUsersItemResponseModel;

  factory GetAppUsersItemResponseModel.fromJson(Map<String, dynamic> json) =>
      _$GetAppUsersItemResponseModelFromJson(json);
}

extension GetUsersResponseModelMapper on GetAppUsersResponseModel {
  List<UserEntity> toEntity() {
    return items.map((GetAppUsersItemResponseModel item) => UserEntity(
        id: item.id,
        delegationId: item.delegationId,
        email: item.email,
        createdAt: item.createdAt,
        updatedAt: item.updatedAt,
        status: item.status,
        role: item.role,
        lastLogin: item.lastLogin,
        currentLogin: item.currentLogin,
        language: item.language,
        firstName: item.firstName,
        lastName: item.lastName,
        hasApiKey: item.hasApiKey,
        phone: item.phone,
    )).toList();
  }
}