using TakeoutSaaS.Domain.Identity.Entities;

namespace TakeoutSaaS.Domain.Identity.Repositories;

/// <summary>
/// 角色模板仓储。
/// </summary>
public interface IRoleTemplateRepository
{
    /// <summary>
    /// 查询角色模板列表。
    /// </summary>
    /// <param name="isActive">启用状态过滤。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>角色模板集合。</returns>
    Task<IReadOnlyList<RoleTemplate>> GetAllAsync(bool? isActive, CancellationToken cancellationToken = default);

    /// <summary>
    /// 通过模板编码获取模板信息。
    /// </summary>
    /// <param name="templateCode">模板编码。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>模板实体或 null。</returns>
    Task<RoleTemplate?> FindByCodeAsync(string templateCode, CancellationToken cancellationToken = default);

    /// <summary>
    /// 获取模板的权限列表。
    /// </summary>
    /// <param name="roleTemplateId">模板 ID。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>权限集合。</returns>
    Task<IReadOnlyList<RoleTemplatePermission>> GetPermissionsAsync(long roleTemplateId, CancellationToken cancellationToken = default);

    /// <summary>
    /// 批量获取多个模板的权限映射。
    /// </summary>
    /// <param name="roleTemplateIds">模板 ID 集合。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>模板与权限列表的映射。</returns>
    Task<IDictionary<long, IReadOnlyList<RoleTemplatePermission>>> GetPermissionsAsync(IEnumerable<long> roleTemplateIds, CancellationToken cancellationToken = default);

    /// <summary>
    /// 新增模板及其权限。
    /// </summary>
    /// <param name="template">模板实体。</param>
    /// <param name="permissionCodes">权限编码集合。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>异步操作任务。</returns>
    Task AddAsync(RoleTemplate template, IEnumerable<string> permissionCodes, CancellationToken cancellationToken = default);

    /// <summary>
    /// 更新模板及权限。
    /// </summary>
    /// <param name="template">模板实体。</param>
    /// <param name="permissionCodes">权限编码集合。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>异步操作任务。</returns>
    Task UpdateAsync(RoleTemplate template, IEnumerable<string> permissionCodes, CancellationToken cancellationToken = default);

    /// <summary>
    /// 删除模板。
    /// </summary>
    /// <param name="roleTemplateId">模板 ID。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>异步操作任务。</returns>
    Task DeleteAsync(long roleTemplateId, CancellationToken cancellationToken = default);

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