using TakeoutSaaS.Domain.Identity.Entities;

namespace TakeoutSaaS.Domain.Identity.Repositories;

/// <summary>
/// 后台用户仓储契约。
/// </summary>
public interface IIdentityUserRepository
{
    /// <summary>
    /// 根据账号获取后台用户。
    /// </summary>
    /// <param name="account">账号。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>后台用户或 null。</returns>
    Task<IdentityUser?> FindByAccountAsync(string account, CancellationToken cancellationToken = default);

    /// <summary>
    /// 判断账号是否存在。
    /// </summary>
    /// <param name="account">账号。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>存在返回 true。</returns>
    Task<bool> ExistsByAccountAsync(string account, CancellationToken cancellationToken = default);

    /// <summary>
    /// 根据 ID 获取后台用户。
    /// </summary>
    /// <param name="userId">用户 ID。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>后台用户或 null。</returns>
    Task<IdentityUser?> FindByIdAsync(long userId, CancellationToken cancellationToken = default);

    /// <summary>
    /// 按租户与关键字查询后台用户列表（仅读）。
    /// </summary>
    /// <param name="tenantId">租户 ID。</param>
    /// <param name="keyword">可选关键字（账号/名称）。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>后台用户列表。</returns>
    Task<IReadOnlyList<IdentityUser>> SearchAsync(long tenantId, string? keyword, CancellationToken cancellationToken = default);

    /// <summary>
    /// 获取指定租户、用户集合对应的用户（只读）。
    /// </summary>
    /// <param name="tenantId">租户 ID。</param>
    /// <param name="userIds">用户 ID 集合。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>后台用户列表。</returns>
    Task<IReadOnlyList<IdentityUser>> GetByIdsAsync(long tenantId, IEnumerable<long> userIds, CancellationToken cancellationToken = default);

    /// <summary>
    /// 新增后台用户。
    /// </summary>
    /// <param name="user">后台用户实体。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>异步操作任务。</returns>
    Task AddAsync(IdentityUser user, CancellationToken cancellationToken = default);

    /// <summary>
    /// 持久化仓储变更。
    /// </summary>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>异步操作任务。</returns>
    Task SaveChangesAsync(CancellationToken cancellationToken = default);
}
