/**
 * Copyright © 2024 Nevis Security AG. All rights reserved.
 */

import { PasswordChangeDeviceProtectionError } from './PasswordChangeDeviceProtectionError';
import { PasswordChangeError } from './PasswordChangeError';
import { PasswordChangeNoDeviceLockError } from './PasswordChangeNoDeviceLockError';
import { PasswordChangePasswordLocked } from './PasswordChangePasswordLocked';
import { PasswordChangePasswordNotEnrolled } from './PasswordChangePasswordNotEnrolled';
import { PasswordChangeUnknownError } from './PasswordChangeUnknownError';
import { PasswordChangeUserCanceled } from './PasswordChangeUserCanceled';
import { PasswordChangeUserNotResponsive } from './PasswordChangeUserNotResponsive';
import { ErrorConverter } from '../../ErrorConverter';

enum PasswordChangeErrorType {
	DeviceProtectionError,
	NoDeviceLockError,
	PasswordLocked,
	PasswordNotEnrolled,
	Unknown,
	UserCanceled,
	UserNotResponsive,
}

export class PasswordChangeErrorConverter extends ErrorConverter<PasswordChangeError> {
	convert(): PasswordChangeError {
		const subtype =
			PasswordChangeErrorType[this.error.type as keyof typeof PasswordChangeErrorType];
		switch (subtype) {
			case PasswordChangeErrorType.DeviceProtectionError:
				return new PasswordChangeDeviceProtectionError(
					this.error.description,
					this.error.cause
				);
			case PasswordChangeErrorType.NoDeviceLockError:
				return new PasswordChangeNoDeviceLockError(
					this.error.description,
					this.error.cause
				);
			case PasswordChangeErrorType.PasswordLocked:
				return new PasswordChangePasswordLocked(this.error.description, this.error.cause);
			case PasswordChangeErrorType.PasswordNotEnrolled:
				return new PasswordChangePasswordNotEnrolled(
					this.error.description,
					this.error.cause
				);
			case PasswordChangeErrorType.Unknown:
				return new PasswordChangeUnknownError(this.error.description, this.error.cause);
			case PasswordChangeErrorType.UserCanceled:
				return new PasswordChangeUserCanceled(this.error.description, this.error.cause);
			case PasswordChangeErrorType.UserNotResponsive:
				return new PasswordChangeUserNotResponsive(
					this.error.description,
					this.error.cause
				);
		}
	}
}
