// Copyright (C) 2022 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';

class ApplyActionCodeFailureFirebase extends ApplyActionCodeFailureInterface {
  ApplyActionCodeFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  ApplyActionCodeFailureFirebase.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.';
    }
  }
}

class SignUpWithEmailAndPasswordFailureFirebase
    extends SignUpWithEmailAndPasswordFailureInterface {
  SignUpWithEmailAndPasswordFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  SignUpWithEmailAndPasswordFailureFirebase.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.';
    }
  }
}

class FetchSignInMethodsForEmailFailureFirebase
    extends FetchSignInMethodsForEmailFailureInterface {
  FetchSignInMethodsForEmailFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  FetchSignInMethodsForEmailFailureFirebase.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.';
    }
  }
}

class SignInAnonymouslyFailureFirebase
    extends SignInAnonymouslyFailureInterface {
  SignInAnonymouslyFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  SignInAnonymouslyFailureFirebase.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.';
    }
  }
}

class SignInWithCredentialFailureFirebase
    extends SignInWithCredentialFailureInterface {
  SignInWithCredentialFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  SignInWithCredentialFailureFirebase.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.';
    }
  }
}

class SignInWithGoogleFailureFirebase
    extends SignInWithCredentialFailureFirebase
    implements SignInWithGoogleFailureInterface {
  SignInWithGoogleFailureFirebase([super.code, super.msg]);
  SignInWithGoogleFailureFirebase.fromCode(super.code) : super.fromCode();
}

class SignInWithFacebookFailureFirebase
    extends SignInWithCredentialFailureFirebase
    implements SignInWithFacebookFailureInterface {
  SignInWithFacebookFailureFirebase([super.code, super.msg]);
  SignInWithFacebookFailureFirebase.fromCode(super.code) : super.fromCode();
}

class SignInWithAppleFailureFirebase extends SignInWithCredentialFailureFirebase
    implements SignInWithAppleFailureInterface {
  SignInWithAppleFailureFirebase([super.code, super.msg]);
  SignInWithAppleFailureFirebase.fromCode(super.code) : super.fromCode();
}

class SignInWithTwitterFailureFirebase
    extends SignInWithCredentialFailureFirebase
    implements SignInWithAppleFailureInterface {
  SignInWithTwitterFailureFirebase([super.code, super.msg]);
  SignInWithTwitterFailureFirebase.fromCode(super.code) : super.fromCode();
}

class SignInWithEmailLinkFailureFirebase
    extends SignInWithEmailLinkFailureInterface {
  SignInWithEmailLinkFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  SignInWithEmailLinkFailureFirebase.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.';
    }
  }
}

class SignInWithEmailAndPasswordFailureFirebase
    extends SignInWithEmailAndPasswordFailureInterface {
  SignInWithEmailAndPasswordFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  SignInWithEmailAndPasswordFailureFirebase.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.';
    }
  }
}

class SendEmailVerificationFailureFirebase
    extends SendEmailVerificationFailureInterface {
  SendEmailVerificationFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');

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

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

class SendSignInLinkEmailFailureFirebase
    extends SendSignInLinkEmailFailureInterface {
  SendSignInLinkEmailFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');

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

class ConfirmPasswordResetFailureFirebase
    extends ConfirmPasswordResetFailureInterface {
  ConfirmPasswordResetFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');

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

class VerifyPasswordResetCodeFailureFirebase
    extends VerifyPasswordResetCodeFailureInterface {
  VerifyPasswordResetCodeFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');

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

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

class SignOutFailureFirebase extends SignOutFailureInterface {
  SignOutFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');

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

class GetIdTokenFailureFirebase extends GetIdTokenFailureInterface {
  GetIdTokenFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');

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

class ReauthenticateFailureFirebase extends ReauthenticateFailureInterface {
  ReauthenticateFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  ReauthenticateFailureFirebase.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.';
    }
  }
}

class UpdateEmailFailureFirebase extends UpdateEmailFailureInterface {
  UpdateEmailFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  UpdateEmailFailureFirebase.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.';
    }
  }
}

class UpdatePasswordFailureFirebase extends UpdatePasswordFailureInterface {
  UpdatePasswordFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
  UpdatePasswordFailureFirebase.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.';
    }
  }
}

class ModelParsingFailureFirebase extends ModelParsingFailureInterface {
  ModelParsingFailureFirebase([String? code, String? msg])
      : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');

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