using System.IdentityModel.Tokens.Jwt;
using adas_core.Authentication.Models;
using adas_core.Domain.Models.DTO;
using adas_core.Domain.Models.Filter;
using adas_core.Domain.Models.MongoModels;
using adas_core.Domain.Models.Responses;
using Microsoft.IdentityModel.Tokens;
using MongoDB.Bson;
namespace adas_core.Authentication.Interfaces;
public interface IUserService
{
static readonly string TokenTypeUser = "user";
static readonly string TokenTypeRefresh = "refresh";
///
/// Authenticates a user with the provided credentials and returns a token result upon successful login.
///
/// The username of the user attempting to log in.
/// The password associated with the specified username.
/// A task that represents the asynchronous login operation, containing the with the authentication token information.
Task Login(string username, string password);
///
/// Authenticates a user based on the provided username and password and returns the corresponding user.
///
/// The username of the user to authenticate.
/// The password of the user to authenticate.
/// A task that represents the asynchronous operation. The task result contains the authenticated .
Task GetUser(string username, string password);
///
/// Refreshes an authentication token using the provided refresh token and returns the resulting token information.
///
/// The refresh token used to obtain a new access token.
/// A that represents the asynchronous operation, containing the with the refreshed token details.
Task RefreshToken(string refreshToken);
///
/// Authenticates a user by exchanging a provided access token for a login result.
///
/// The access token used to authenticate the user.
/// A task that represents the asynchronous login operation, containing the with the outcome of the authentication.
Task LoginWithAccessToken(string token);
///
/// Validates the specified token according to its type and outputs the corresponding .
///
/// The token string to be validated.
/// The type of the token, used to determine the appropriate validation strategy.
/// When the method returns, contains the validated if validation succeeds.
void ValidateToken(string token, string tokenType, out SecurityToken securityToken);
///
/// Retrieves the user associated with the provided JWT security token.
/// Returns null if the token is null or if no matching user is found.
///
/// The JWT security token used to identify the user. May be null.
/// A task that resolves to the associated with the token, or null if the token is invalid or no user matches.
Task GetUserByToken(JwtSecurityToken? jwtToken);
///
/// Asynchronously retrieves a user by validating a CAS (Central Authentication Service) ticket against the specified service.
///
/// The service URL or identifier that the ticket was issued for and must be validated against.
/// The CAS ticket string used to authenticate and identify the user.
/// A task that represents the asynchronous operation. The task result contains the associated if the ticket is valid, or null if the user cannot be found.
Task GetUserByCasTicket(string service, string ticket);
///
/// Asynchronously generates a JSON Web Token (JWT) for the specified user and returns the token result.
///
/// The user for whom the JWT is being generated.
/// A task that represents the asynchronous operation, containing the with the generated token details.
Task GenerateJwt(User user);
///
/// Asynchronously retrieves all users from the data store.
///
/// A task that represents the asynchronous operation. The task result contains a list of all entities.
Task> GetAll();
///
/// Asynchronously retrieves a user by their unique identifier, returning null when no user matches the provided id.
///
/// The unique identifier of the user to look up.
/// A task that resolves to the matching , or null if no user is found for the given id.
Task GetUserById(ObjectId id);
///
/// Asynchronously retrieves a user by their unique username, returning null when no matching user is found.
///
/// The username used to look up the user.
/// A task that represents the asynchronous operation, containing the matching user if found; otherwise, null.
Task GetUserByUserName(string name);
///
/// Asynchronously retrieves a user matching the specified name, returning null when no matching user is found.
///
/// The name used to look up the user.
/// A task that resolves to the matching , or null if no user with the given name exists.
Task GetUserByName(string name);
///
/// Creates a user from the provided LDAP user entry.
///
/// The LDAP user entry used to create the user.
/// A task that represents the asynchronous create operation, containing the created or null.
Task CreateUser(User userEntryLdap);
///
/// Creates a new user based on the provided user data, typically originating from an incoming request.
/// Returns the newly created user, or if the user could not be created.
///
/// The user data to use for creating the new user.
/// A task that represents the asynchronous operation. The result is the created , or if creation failed.
Task CreateNewUserByRequest(User user);
///
/// Creates a new user together with the associated authorities based on the supplied data transfer object.
///
/// The data transfer object containing the information required to create the user and its authorities.
/// A task that represents the asynchronous operation. The task result contains the created instance, or null if no user was created.
Task CreateNewUserWithAuthorities(CreateUserWithAuthDto createUserWithAuthDto);
///
/// Updates an existing user along with the associated authorities, optionally updating the password.
///
/// The data transfer object containing the user information and authorities to update.
/// A flag indicating whether the user's password should be updated as part of the operation.
/// A task that represents the asynchronous operation, containing the updated or null if the user was not found.
Task UpdateUserWithAuthorities(UpdateUserWithAuthDto createUserWithAuthDto, bool updatePass);
///
/// Updates a user's information based on the provided user data, with an option to include password updates.
///
/// The user entity containing the updated information to be persisted.
/// A flag indicating whether the user's password should be updated during this operation.
/// A task that returns the updated , or null if the user could not be found.
Task UpdateUsersByRequest(User user, bool updatePass);
///
/// Updates the password for the user identified by the specified identifier, verifying the old password before applying the new one.
///
/// The unique identifier of the user whose password will be updated.
/// The user's current password, used to verify the request.
/// The new password to set for the user.
/// A task that represents the asynchronous operation. The task result is true if the password was updated successfully; otherwise, false.
Task UpdateUserPassword(ObjectId id, string oldPassword, string newPassword);
///
/// Asynchronously deletes a user identified by the specified identifier.
///
/// The unique identifier of the user to delete.
/// A task that represents the asynchronous operation, containing a value indicating whether the user was successfully deleted.
Task DeleteUser(ObjectId id);
///
/// Retrieves a paginated list of users based on the provided pagination filter configuration.
///
/// The pagination filter that defines paging parameters such as page number and page size.
/// A task that represents the asynchronous operation, containing the paginated response of entries.
Task> GetPaginatedUsers(PaginationFilter config);
///
/// Asynchronously creates a new authority based on the provided authorization data.
///
/// The authorization information used to create the new authority.
/// A task that represents the asynchronous operation. The task result contains the created .
Task CreateNewAuthority(Authorization auth);
///
/// Asynchronously deletes an authority identified by the specified identifier.
///
/// The unique identifier of the authority to delete.
/// A task that represents the asynchronous delete operation. The task result contains a boolean indicating whether the authority was successfully deleted.
Task DeleteAuthority(string id);
///
/// Updates the authority information based on the provided authorization data.
///
/// The authorization entity containing the authority details to be updated.
/// A task that represents the asynchronous operation. The task result is true if the update was successful; otherwise, false.
Task UpdateAuthority(Authorization authorization);
///
/// Authenticates the user using the provided access token and returns the resulting token information.
///
/// The access token used to perform the login.
/// A task that represents the asynchronous login operation, containing the token result.
Task LoginWithGivenAccessToken(string token);
}