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

part 'get_logged_user_response_model.freezed.dart';
part 'get_logged_user_response_model.g.dart';

@freezed
abstract class GetLoggedUserResponseModel with _$GetLoggedUserResponseModel {
  const factory GetLoggedUserResponseModel({
    required GetLoggedUserItemResponseModel item,
  }) = _GetLoggedUserResponseModel;

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

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

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

extension GetLoggedUserResponseModelMapper on GetLoggedUserResponseModel {
  UserEntity toEntity() {
    return 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 ?? ''
    );
  }
}