// Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

part of 'exceptions.dart';

/// {@macro apply_action_code_failure}
class ApplyActionCodeFailureMock extends ApplyActionCodeFailureInterface {
  ApplyActionCodeFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  ApplyActionCodeFailureMock.fromCode(String code) : super.fromCode(code) {
    switch (code) {
      case 'expired-action-code':
        msg = 'Action code has expired.';
        break;
      case 'invalid-action-code':
        msg = 'Action code is invalid.';
        break;
      case 'user-disabled':
        msg = 'This user has been disabled. Please contact support for help.';
        break;
      case 'user-not-found':
        msg = 'Email is not found, please create an account.';
        break;

      default:
        this.code = 'unknown';
        msg = 'An unknown error occurred.';
    }
  }
}

/// {@macro sign_up_with_email_and_password_failure}
class SignUpWithEmailAndPasswordFailureMock
    extends SignUpWithEmailAndPasswordFailureInterface {
  SignUpWithEmailAndPasswordFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  SignUpWithEmailAndPasswordFailureMock.fromCode(String code)
      : super.fromCode(code) {
    switch (code) {
      case 'invalid-email':
        msg = 'The email address is badly formatted.';
        break;
      case 'user-disabled':
        msg = 'This user has been disabled. Please contact support for help.';
        break;
      case 'email-already-in-use':
        msg = 'An account already exists for that email.';
        break;
      case 'operation-not-allowed':
        msg = 'Operation is not allowed. Please contact support.';
        break;
      case 'weak-password':
        msg = 'Please enter a stronger password.';
        break;
      default:
        this.code = 'unknown';
        msg = 'An unknown error occurred.';
    }
  }
}

/// {@macro fetch_sign_in_methods_failure}
class FetchSignInMethodsForEmailFailureMock
    extends FetchSignInMethodsForEmailFailureInterface {
  FetchSignInMethodsForEmailFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  FetchSignInMethodsForEmailFailureMock.fromCode(String code)
      : super.fromCode(code) {
    switch (code) {
      case 'invalid-email':
        msg = 'The email address is badly formatted.';
        break;
      default:
        this.code = 'unknown';
        msg = 'An unknown error occurred.';
    }
  }
}

/// {@macro sign_in_anonymously_failure}
class SignInAnonymouslyFailureMock
    extends SignInAnonymouslyFailureInterface {
  SignInAnonymouslyFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  SignInAnonymouslyFailureMock.fromCode(String code)
      : super.fromCode(code) {
    switch (code) {
      case 'operation-not-allowed':
        msg = 'Operation is not allowed. Please contact support.';
        break;
      default:
        this.code = 'unknown';
        msg = 'An unknown error occurred.';
    }
  }
}

/// {@macro sign_in_with_credential_failure}
class SignInWithCredentialFailureMock
    extends SignInWithCredentialFailureInterface {
  SignInWithCredentialFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  SignInWithCredentialFailureMock.fromCode(String code)
      : super.fromCode(code) {
    switch (code) {
      case 'account-exists-with-different-credential':
        msg = 'Account exists with different credentials.';
        break;
      case 'invalid-credential':
        msg = 'The credential received is malformed or has expired.';
        break;
      case 'operation-not-allowed':
        msg = 'Operation is not allowed. Please contact support.';
        break;
      case 'user-disabled':
        msg = 'This user has been disabled. Please contact support for help.';
        break;
      case 'user-not-found':
        msg = 'Email is not found, please create an account.';
        break;
      case 'wrong-password':
        msg = 'Incorrect password, please try again.';
        break;
      case 'invalid-verification-code':
        msg = 'The credential verification code received is invalid.';
        break;
      case 'invalid-verification-id':
        msg = 'The credential verification ID received is invalid.';
        break;
      default:
        this.code = 'unknown';
        msg = 'An unknown error occurred.';
    }
  }
}

/// {@macro sign_in_with_google_failure}
class SignInWithGoogleFailureMock
    extends SignInWithCredentialFailureMock
    implements SignInWithGoogleFailureInterface {
  SignInWithGoogleFailureMock([super.code, super.msg]);
  SignInWithGoogleFailureMock.fromCode(super.code) : super.fromCode();
}

/// {@macro sign_in_with_facebook_failure}
class SignInWithFacebookFailureMock
    extends SignInWithCredentialFailureMock
    implements SignInWithFacebookFailureInterface {
  SignInWithFacebookFailureMock([super.code, super.msg]);
  SignInWithFacebookFailureMock.fromCode(super.code) : super.fromCode();
}

/// {@macro sign_in_with_apple_failure}
class SignInWithAppleFailureMock extends SignInWithCredentialFailureMock
    implements SignInWithAppleFailureInterface {
  SignInWithAppleFailureMock([super.code, super.msg]);
  SignInWithAppleFailureMock.fromCode(super.code) : super.fromCode();
}

/// {@macro sign_in_with_twitter_failure}
class SignInWithTwitterFailureMock
    extends SignInWithCredentialFailureMock
    implements SignInWithAppleFailureInterface {
  SignInWithTwitterFailureMock([super.code, super.msg]);
  SignInWithTwitterFailureMock.fromCode(super.code) : super.fromCode();
}

/// {@macro sign_in_with_email_link_failure}
class SignInWithEmailLinkFailureMock
    extends SignInWithEmailLinkFailureInterface {
  SignInWithEmailLinkFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  SignInWithEmailLinkFailureMock.fromCode(String code)
      : super.fromCode(code) {
    switch (code) {
      case 'expired-action-code':
        msg = 'Action code has expired.';
        break;
      case 'invalid-email':
        msg = 'Email is not valid or badly formatted.';
        break;
      case 'user-disabled':
        msg = 'This user has been disabled. Please contact support for help.';
        break;
      default:
        this.code = 'unknown';
        msg = 'An unknown error occurred.';
    }
  }
}

/// {@macro sign_in_with_email_and_password_failure}
class SignInWithEmailAndPasswordFailureMock
    extends SignInWithEmailAndPasswordFailureInterface {
  SignInWithEmailAndPasswordFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  SignInWithEmailAndPasswordFailureMock.fromCode(String code)
      : super.fromCode(code) {
    switch (code) {
      case 'invalid-email':
        msg = 'Email is not valid or badly formatted.';
        break;
      case 'user-disabled':
        msg = 'This user has been disabled. Please contact support for help.';
        break;
      case 'user-not-found':
        msg = 'Email is not found, please create an account.';
        break;
      case 'wrong-password':
        msg = 'Incorrect password, please try again.';
        break;
      default:
        this.code = 'unknown';
        msg = 'An unknown error occurred.';
    }
  }
}

/// {@macro send_email_verification_failure}
class SendEmailVerificationFailureMock
    extends SendEmailVerificationFailureInterface {
  SendEmailVerificationFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');

  SendEmailVerificationFailureMock.fromCode(super.code) : super.fromCode();
}

/// {@macro send_password_reset_email_failure}
class SendPasswordResetEmailFailureMock
    extends SendPasswordResetEmailFailureInterface {
  SendPasswordResetEmailFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  SendPasswordResetEmailFailureMock.fromCode(super.code) : super.fromCode();
}

/// {@macro send_sign_in_link_email_failure}
class SendSignInLinkEmailFailureMock
    extends SendSignInLinkEmailFailureInterface {
  SendSignInLinkEmailFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');

  SendSignInLinkEmailFailureMock.fromCode(super.code) : super.fromCode();
}

/// {@macro confirm_password_reset_failure}
class ConfirmPasswordResetFailureMock
    extends ConfirmPasswordResetFailureInterface {
  ConfirmPasswordResetFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');

  ConfirmPasswordResetFailureMock.fromCode(super.code) : super.fromCode();
}

/// {@macro verify_password_reset_code_failure}
class VerifyPasswordResetCodeFailureMock
    extends VerifyPasswordResetCodeFailureInterface {
  VerifyPasswordResetCodeFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');

  VerifyPasswordResetCodeFailureMock.fromCode(super.code)
      : super.fromCode();
}

/// {@macro refresh_failure}
class RefreshFailureMock extends RefreshFailureInterface {
  RefreshFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  RefreshFailureMock.fromCode(super.code) : super.fromCode();
}

/// {@macro sign_out_failure}
class SignOutFailureMock extends SignOutFailureInterface {
  SignOutFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');

  SignOutFailureMock.fromCode(super.code) : super.fromCode();
}

/// {@macro reauthenticate_failure}
class ReauthenticateFailureMock extends ReauthenticateFailureInterface {
  ReauthenticateFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  ReauthenticateFailureMock.fromCode(String code) : super.fromCode(code) {
    switch (code) {
      case 'user-mismatch':
        msg = 'Given credential does not correspond to the user.';
        break;
      case 'user-not-found':
        msg = 'User is not found, please create an account.';
        break;
      case 'invalid-credential':
        msg = 'The credential received is malformed or has expired.';
        break;
      case 'invalid-email':
        msg = 'Email is not valid or badly formatted.';
        break;
      case 'wrong-password':
        msg = 'Incorrect password, please try again.';
        break;
      case 'invalid-verification-code':
        msg = 'The credential verification code received is invalid.';
        break;
      case 'invalid-verification-id':
        msg = 'The credential verification ID received is invalid.';
        break;
      default:
        this.code = 'unknown';
        msg = 'An unknown error occurred.';
    }
  }
}

/// {@macro update_email_failure}
class UpdateEmailFailureMock extends UpdateEmailFailureInterface {
  UpdateEmailFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  UpdateEmailFailureMock.fromCode(String code) : super.fromCode(code) {
    switch (code) {
      case 'invalid-email':
        msg = 'Email is not valid or badly formatted.';
        break;
      case 'email-already-in-use':
        msg = 'An account already exists for that email.';
        break;
      case 'requires-recent-login':
        msg = "User's last sign-in time does not meet the security threshold.";
        break;
      default:
        this.code = 'unknown';
        msg = 'An unknown error occurred.';
    }
  }
}

/// {@macro update_password_failure}
class UpdatePasswordFailureMock extends UpdatePasswordFailureInterface {
  UpdatePasswordFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  UpdatePasswordFailureMock.fromCode(String code) : super.fromCode(code) {
    switch (code) {
      case 'weak-password':
        msg = 'Please enter a stronger password.';
        break;
      case 'requires-recent-login':
        msg = "User's last sign-in time does not meet the security threshold.";
        break;
      default:
        this.code = 'unknown';
        msg = 'An unknown error occurred.';
    }
  }
}

/// {@macro model_parsing_failure}
class ModelParsingFailureMock extends ModelParsingFailureInterface {
  ModelParsingFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');

  ModelParsingFailureMock.fromCode(super.code) : super.fromCode();
}

/// {@macro delete_account_failure}
class DeleteAccountFailureMock extends DeleteAccountFailureInterface {
  DeleteAccountFailureMock([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');

  DeleteAccountFailureMock.fromCode(String code) : super.fromCode(code) {
    switch (code) {
      case 'requires-recent-login':
        msg = "User's last sign-in time does not meet the security threshold.";
        break;
      default:
        this.code = 'unknown';
        msg = 'An unknown error occurred.';
    }
  }
}
