// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:plugin_platform_interface/plugin_platform_interface.dart';

import 'default_method_channel_platform.dart';
import 'types/types.dart';

export 'types/types.dart';

/// The interface that implementations of local_auth must implement.
///
/// Platform implementations should extend this class rather than implement it as `local_auth`
/// does not consider newly added methods to be breaking changes. Extending this class
/// (using `extends`) ensures that the subclass will get the default implementation, while
/// platform implementations that `implements` this interface will be broken by newly added
/// [LocalAuthPlatform] methods.
abstract class LocalAuthPlatform extends PlatformInterface {
  /// Constructs a LocalAuthPlatform.
  LocalAuthPlatform() : super(token: _token);

  static final Object _token = Object();

  static LocalAuthPlatform _instance = DefaultLocalAuthPlatform();

  /// The default instance of [LocalAuthPlatform] to use.
  ///
  /// Defaults to [DefaultLocalAuthPlatform].
  static LocalAuthPlatform get instance => _instance;

  /// Platform-specific implementations should set this with their own
  /// platform-specific class that extends [LocalAuthPlatform] when they
  /// register themselves.
  static set instance(LocalAuthPlatform instance) {
    PlatformInterface.verifyToken(instance, _token);
    _instance = instance;
  }

  /// Authenticates the user with biometrics available on the device while also
  /// allowing the user to use device authentication - pin, pattern, passcode.
  ///
  /// Returns true if the user successfully authenticated. Returns false if
  /// the authentication completes, but the user failed the challenge with no
  /// further effects. Platform implementations should throw a
  /// [LocalAuthException] for any other outcome, such as errors, cancelation,
  /// or lockout. This may mean that for some platforms, the implementation will
  /// never return false (e.g., if the only standard outcomes are success,
  /// cancelation, or temporary lockout due to too many retries).
  ///
  /// [localizedReason] is the message to show to user while prompting them
  /// for authentication. This is typically along the lines of: 'Please scan
  /// your finger to access MyApp.'. This must not be empty.
  ///
  /// Provide [authMessages] if you want to
  /// customize messages in the dialogs.
  ///
  /// Provide [options] for configuring further authentication related options.
  Future<bool> authenticate({
    required String localizedReason,
    required Iterable<AuthMessages> authMessages,
    AuthenticationOptions options = const AuthenticationOptions(),
  }) async {
    throw UnimplementedError('authenticate() has not been implemented.');
  }

  /// Returns true if the device is capable of checking biometrics.
  ///
  /// This will return true even if there are no biometrics currently enrolled.
  Future<bool> deviceSupportsBiometrics() async {
    throw UnimplementedError('canCheckBiometrics() has not been implemented.');
  }

  /// Returns a list of enrolled biometrics.
  ///
  /// Possible values include:
  /// - BiometricType.face
  /// - BiometricType.fingerprint
  /// - BiometricType.iris (not yet implemented)
  /// - BiometricType.strong
  /// - BiometricType.weak
  Future<List<BiometricType>> getEnrolledBiometrics() async {
    throw UnimplementedError(
      'getAvailableBiometrics() has not been implemented.',
    );
  }

  /// Returns true if device is capable of checking biometrics or is able to
  /// fail over to device credentials.
  Future<bool> isDeviceSupported() async {
    throw UnimplementedError('isDeviceSupported() has not been implemented.');
  }

  /// Cancels any authentication currently in progress.
  ///
  /// Returns true if auth was cancelled successfully.
  /// Returns false if there was no authentication in progress,
  /// or an error occurred.
  Future<bool> stopAuthentication() async {
    throw UnimplementedError('stopAuthentication() has not been implemented.');
  }
}
