using TakeoutSaaS.Domain.Identity.Entities;

namespace TakeoutSaaS.Domain.Identity.Repositories;

/// <summary>
/// 权限仓储。
/// </summary>
public interface IPermissionRepository
{
    /// <summary>
    /// 根据 ID 查询权限。
    /// </summary>
    /// <param name="permissionId">权限 ID。</param>
    /// <param name="tenantId">租户 ID。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>权限实体或 null。</returns>
    Task<Permission?> FindByIdAsync(long permissionId, long tenantId, CancellationToken cancellationToken = default);

    /// <summary>
    /// 根据编码查询权限。
    /// </summary>
    /// <param name="code">权限编码。</param>
    /// <param name="tenantId">租户 ID。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>权限实体或 null。</returns>
    Task<Permission?> FindByCodeAsync(string code, long tenantId, CancellationToken cancellationToken = default);

    /// <summary>
    /// 根据编码集合查询权限列表。
    /// </summary>
    /// <param name="tenantId">租户 ID。</param>
    /// <param name="codes">权限编码集合。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>权限集合。</returns>
    Task<IReadOnlyList<Permission>> GetByCodesAsync(long tenantId, IEnumerable<string> codes, CancellationToken cancellationToken = default);

    /// <summary>
    /// 根据 ID 集合查询权限列表。
    /// </summary>
    /// <param name="tenantId">租户 ID。</param>
    /// <param name="permissionIds">权限 ID 集合。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>权限集合。</returns>
    Task<IReadOnlyList<Permission>> GetByIdsAsync(long tenantId, IEnumerable<long> permissionIds, CancellationToken cancellationToken = default);

    /// <summary>
    /// 按关键字搜索权限。
    /// </summary>
    /// <param name="tenantId">租户 ID。</param>
    /// <param name="keyword">关键字。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>权限集合。</returns>
    Task<IReadOnlyList<Permission>> SearchAsync(long tenantId, string? keyword, CancellationToken cancellationToken = default);

    /// <summary>
    /// 新增权限。
    /// </summary>
    /// <param name="permission">权限实体。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>异步操作任务。</returns>
    Task AddAsync(Permission permission, CancellationToken cancellationToken = default);

    /// <summary>
    /// 更新权限。
    /// </summary>
    /// <param name="permission">权限实体。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>异步操作任务。</returns>
    Task UpdateAsync(Permission permission, CancellationToken cancellationToken = default);

    /// <summary>
    /// 删除权限。
    /// </summary>
    /// <param name="permissionId">权限 ID。</param>
    /// <param name="tenantId">租户 ID。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>异步操作任务。</returns>
    Task DeleteAsync(long permissionId, long tenantId, CancellationToken cancellationToken = default);

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