/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/openiddict/openiddict-core for more information concerning
* the license and the contributors participating to this project.
*/
using System.Collections.Immutable;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Text.Json;
namespace OpenIddict.Abstractions;
///
/// Provides methods allowing to manage the scopes stored in the store.
///
///
/// Note: this interface is not meant to be implemented by custom managers,
/// that should inherit from the generic OpenIddictScopeManager class.
/// It is primarily intended to be used by services that cannot easily
/// depend on the generic scope manager. The actual scope entity type is
/// automatically determined at runtime based on the OpenIddict core options.
///
public interface IOpenIddictScopeManager
{
///
/// Determines the number of scopes that exist in the database.
///
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns the number of scopes in the database.
///
ValueTask CountAsync(CancellationToken cancellationToken = default);
///
/// Determines the number of scopes that match the specified query.
///
/// The result type.
/// The query to execute.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns the number of scopes that match the specified query.
///
ValueTask CountAsync(Func, IQueryable> query, CancellationToken cancellationToken = default);
///
/// Creates a new scope based on the specified descriptor.
///
/// The scope descriptor.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation, whose result returns the scope.
///
ValueTask CreateAsync(OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default);
///
/// Creates a new scope.
///
/// The scope to create.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation.
///
ValueTask CreateAsync(object scope, CancellationToken cancellationToken = default);
///
/// Removes an existing scope.
///
/// The scope to delete.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation.
///
ValueTask DeleteAsync(object scope, CancellationToken cancellationToken = default);
///
/// Retrieves a scope using its unique identifier.
///
/// The unique identifier associated with the scope.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns the scope corresponding to the identifier.
///
ValueTask FindByIdAsync(string identifier, CancellationToken cancellationToken = default);
///
/// Retrieves a scope using its name.
///
/// The name associated with the scope.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns the scope corresponding to the specified name.
///
ValueTask FindByNameAsync(string name, CancellationToken cancellationToken = default);
///
/// Retrieves a list of scopes using their name.
///
/// The names associated with the scopes.
/// The that can be used to abort the operation.
/// The scopes corresponding to the specified names.
IAsyncEnumerable FindByNamesAsync(ImmutableArray names, CancellationToken cancellationToken = default);
///
/// Retrieves all the scopes that contain the specified resource.
///
/// The resource associated with the scopes.
/// The that can be used to abort the operation.
/// The scopes associated with the specified resource.
IAsyncEnumerable FindByResourceAsync(string resource, CancellationToken cancellationToken = default);
///
/// Executes the specified query and returns the first element.
///
/// The result type.
/// The query to execute.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
///
ValueTask GetAsync(
Func, IQueryable> query, CancellationToken cancellationToken = default);
///
/// Executes the specified query and returns the first element.
///
/// The state type.
/// The result type.
/// The query to execute.
/// The optional state.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
///
ValueTask GetAsync(
Func, TState, IQueryable> query,
TState state, CancellationToken cancellationToken = default);
///
/// Retrieves the description associated with a scope.
///
/// The scope.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns the description associated with the specified scope.
///
ValueTask GetDescriptionAsync(object scope, CancellationToken cancellationToken = default);
///
/// Retrieves the localized descriptions associated with an scope.
///
/// The scope.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns all the localized descriptions associated with the scope.
///
ValueTask> GetDescriptionsAsync(object scope, CancellationToken cancellationToken = default);
///
/// Retrieves the display name associated with a scope.
///
/// The scope.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns the display name associated with the scope.
///
ValueTask GetDisplayNameAsync(object scope, CancellationToken cancellationToken = default);
///
/// Retrieves the localized display names associated with an scope.
///
/// The scope.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns all the localized display names associated with the scope.
///
ValueTask> GetDisplayNamesAsync(object scope, CancellationToken cancellationToken = default);
///
/// Retrieves the unique identifier associated with a scope.
///
/// The scope.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns the unique identifier associated with the scope.
///
ValueTask GetIdAsync(object scope, CancellationToken cancellationToken = default);
///
/// Retrieves the localized description associated with an scope
/// and corresponding to the current UI culture or one of its parents.
/// If no matching value can be found, the non-localized value is returned.
///
/// The scope.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns the matching localized description associated with the scope.
///
ValueTask GetLocalizedDescriptionAsync(object scope, CancellationToken cancellationToken = default);
///
/// Retrieves the localized description associated with an scope
/// and corresponding to the specified culture or one of its parents.
/// If no matching value can be found, the non-localized value is returned.
///
/// The scope.
/// The culture (typically ).
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns the matching localized description associated with the scope.
///
ValueTask GetLocalizedDescriptionAsync(object scope, CultureInfo culture, CancellationToken cancellationToken = default);
///
/// Retrieves the localized display name associated with an scope
/// and corresponding to the current UI culture or one of its parents.
/// If no matching value can be found, the non-localized value is returned.
///
/// The scope.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns the display name associated with the scope.
///
ValueTask GetLocalizedDisplayNameAsync(object scope, CancellationToken cancellationToken = default);
///
/// Retrieves the localized display name associated with an scope
/// and corresponding to the specified culture or one of its parents.
/// If no matching value can be found, the non-localized value is returned.
///
/// The scope.
/// The culture (typically ).
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns the display name associated with the scope.
///
ValueTask GetLocalizedDisplayNameAsync(object scope, CultureInfo culture, CancellationToken cancellationToken = default);
///
/// Retrieves the name associated with a scope.
///
/// The scope.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns the name associated with the specified scope.
///
ValueTask GetNameAsync(object scope, CancellationToken cancellationToken = default);
///
/// Retrieves the additional properties associated with a scope.
///
/// The scope.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns all the additional properties associated with the scope.
///
ValueTask> GetPropertiesAsync(object scope, CancellationToken cancellationToken = default);
///
/// Retrieves the resources associated with a scope.
///
/// The scope.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation,
/// whose result returns all the resources associated with the scope.
///
ValueTask> GetResourcesAsync(object scope, CancellationToken cancellationToken = default);
///
/// Executes the specified query and returns all the corresponding elements.
///
/// The number of results to return.
/// The number of results to skip.
/// The that can be used to abort the operation.
/// All the elements returned when executing the specified query.
IAsyncEnumerable ListAsync(
int? count = null, int? offset = null, CancellationToken cancellationToken = default);
///
/// Executes the specified query and returns all the corresponding elements.
///
/// The result type.
/// The query to execute.
/// The that can be used to abort the operation.
/// All the elements returned when executing the specified query.
IAsyncEnumerable ListAsync(
Func, IQueryable> query, CancellationToken cancellationToken = default);
///
/// Executes the specified query and returns all the corresponding elements.
///
/// The state type.
/// The result type.
/// The query to execute.
/// The optional state.
/// The that can be used to abort the operation.
/// All the elements returned when executing the specified query.
IAsyncEnumerable ListAsync(
Func, TState, IQueryable> query,
TState state, CancellationToken cancellationToken = default);
///
/// Lists all the resources associated with the specified scopes.
///
/// The scopes.
/// The that can be used to abort the operation.
/// All the resources associated with the specified scopes.
IAsyncEnumerable ListResourcesAsync(ImmutableArray scopes, CancellationToken cancellationToken = default);
///
/// Populates the specified descriptor using the properties exposed by the scope.
///
/// The descriptor.
/// The scope.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation.
///
ValueTask PopulateAsync(OpenIddictScopeDescriptor descriptor, object scope, CancellationToken cancellationToken = default);
///
/// Populates the scope using the specified descriptor.
///
/// The scope.
/// The descriptor.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation.
///
ValueTask PopulateAsync(object scope, OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default);
///
/// Updates an existing scope.
///
/// The scope to update.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation.
///
ValueTask UpdateAsync(object scope, CancellationToken cancellationToken = default);
///
/// Updates an existing scope.
///
/// The scope to update.
/// The descriptor used to update the scope.
/// The that can be used to abort the operation.
///
/// A that can be used to monitor the asynchronous operation.
///
ValueTask UpdateAsync(object scope, OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default);
///
/// Validates the scope to ensure it's in a consistent state.
///
/// The scope.
/// The that can be used to abort the operation.
/// The validation error encountered when validating the scope.
IAsyncEnumerable ValidateAsync(object scope, CancellationToken cancellationToken = default);
}