part of '../auth_dtos.dart';

@freezed
class LoginDto with _$LoginDto {
  const LoginDto._();

  const factory LoginDto({
    @JsonKey(name: "token") String? token,
    @JsonKey(name: "refresh_token") String? refreshToken,
    @JsonKey(name: "expires_at") String? expiresAt,
    @JsonKey(name: "refresh_expires_at") String? refreshExpiresAt,
    @JsonKey(name: "user") UserDto? user,
  }) = _LoginDto;

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

  /// mapping ke domain
  Login toDomain() => Login(
    token: token ?? '',
    refreshToken: refreshToken ?? '',
    expiresAt: expiresAt ?? '',
    refreshExpiresAt: refreshExpiresAt ?? '',
    user:
        user?.toDomain() ??
        User(
          id: '',
          organizationId: '',
          outletId: '',
          name: '',
          email: '',
          role: '',
          permissions: {},
          isActive: false,
          createdAt: '',
          updatedAt: '',
        ),
  );
}
