/*
* Copyright (c) 2022 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Plugins.Essentials
* File: IUserManager.cs
*
* IUserManager.cs is part of VNLib.Plugins.Essentials which is part of the larger
* VNLib collection of libraries and utilities.
*
* VNLib.Plugins.Essentials is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* VNLib.Plugins.Essentials 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
using System;
using System.Threading;
using System.Threading.Tasks;
using VNLib.Utils;
using VNLib.Utils.Memory;
#nullable enable
namespace VNLib.Plugins.Essentials.Users
{
///
/// A backing store that provides user accounts
///
public interface IUserManager
{
///
/// Attempts to get a user object without their password from the database asynchronously
///
/// The id of the user
/// A token to cancel the operation
/// The user's object, null if the user was not found
///
Task GetUserFromIDAsync(string userId, CancellationToken cancellationToken = default);
///
/// Attempts to get a user object without their password from the database asynchronously
///
/// The user's email address
/// A token to cancel the operation
/// The user's object, null if the user was not found
///
Task GetUserFromEmailAsync(string emailAddress, CancellationToken cancellationToken = default);
///
/// Attempts to get a user object with their password from the database on the current thread
///
/// The id of the user
/// A token to cancel the operation
/// The user's object, null if the user was not found
///
Task GetUserAndPassFromIDAsync(string userid, CancellationToken cancellation = default);
///
/// Attempts to get a user object with their password from the database asynchronously
///
/// The user's email address
/// A token to cancel the operation
/// The user's object, null if the user was not found
///
Task GetUserAndPassFromEmailAsync(string emailAddress, CancellationToken cancellationToken = default);
///
/// Creates a new user in the current user's table and if successful returns the new user object (without password)
///
/// The user id
/// A number representing the privilage level of the account
/// Value to store in the password field
/// A token to cancel the operation
/// The account email address
/// An object representing a user's account if successful, null otherwise
///
///
///
Task CreateUserAsync(string userid, string emailAddress, ulong privilages, PrivateString passHash, CancellationToken cancellation = default);
///
/// Updates a password associated with the specified user. If the update fails, the transaction
/// is rolled back.
///
/// The user account to update the password of
/// The new password to set
/// A token to cancel the operation
/// The result of the operation, the result should be 1 (aka true)
Task UpdatePassAsync(IUser user, PrivateString newPass, CancellationToken cancellation = default);
///
/// Gets the number of entries in the current user table
///
/// A token to cancel the operation
/// The number of users in the table, or -1 if the operation failed
Task GetUserCountAsync(CancellationToken cancellation = default);
}
}