using TakeoutSaaS.Domain.Dictionary.Entities;
using TakeoutSaaS.Domain.Dictionary.Enums;
using TakeoutSaaS.Domain.Dictionary.ValueObjects;

namespace TakeoutSaaS.Domain.Dictionary.Repositories;

/// <summary>
/// 字典分组仓储契约。
/// </summary>
public interface IDictionaryGroupRepository
{
    /// <summary>
    /// 按 ID 获取字典分组。
    /// </summary>
    /// <param name="groupId">分组 ID。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>分组实体或 null。</returns>
    Task<DictionaryGroup?> GetByIdAsync(long groupId, CancellationToken cancellationToken = default);

    /// <summary>
    /// 按编码获取字典分组。
    /// </summary>
    /// <param name="tenantId">租户 ID。</param>
    /// <param name="code">分组编码。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>分组实体或 null。</returns>
    Task<DictionaryGroup?> GetByCodeAsync(long tenantId, DictionaryCode code, CancellationToken cancellationToken = default);

    /// <summary>
    /// 分页获取字典分组。
    /// </summary>
    /// <param name="tenantId">租户 ID。</param>
    /// <param name="scope">作用域过滤。</param>
    /// <param name="keyword">关键字过滤。</param>
    /// <param name="isEnabled">启用状态过滤。</param>
    /// <param name="page">页码。</param>
    /// <param name="pageSize">页大小。</param>
    /// <param name="sortBy">排序字段。</param>
    /// <param name="sortDescending">是否降序。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>分组集合。</returns>
    Task<IReadOnlyList<DictionaryGroup>> GetPagedAsync(
        long tenantId,
        DictionaryScope? scope,
        string? keyword,
        bool? isEnabled,
        int page,
        int pageSize,
        string? sortBy,
        bool sortDescending,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 获取满足条件的分组数量。
    /// </summary>
    /// <param name="tenantId">租户 ID。</param>
    /// <param name="scope">作用域过滤。</param>
    /// <param name="keyword">关键字过滤。</param>
    /// <param name="isEnabled">启用状态过滤。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>分组数量。</returns>
    Task<int> CountAsync(
        long tenantId,
        DictionaryScope? scope,
        string? keyword,
        bool? isEnabled,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 批量获取字典分组。
    /// </summary>
    /// <param name="groupIds">分组 ID 列表。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>分组集合。</returns>
    Task<IReadOnlyList<DictionaryGroup>> GetByIdsAsync(IEnumerable<long> groupIds, CancellationToken cancellationToken = default);

    /// <summary>
    /// 新增分组。
    /// </summary>
    /// <param name="group">分组实体。</param>
    /// <param name="cancellationToken">取消标记。</param>
    Task AddAsync(DictionaryGroup group, CancellationToken cancellationToken = default);

    /// <summary>
    /// 更新分组。
    /// </summary>
    /// <param name="group">分组实体。</param>
    /// <param name="cancellationToken">取消标记。</param>
    Task UpdateAsync(DictionaryGroup group, CancellationToken cancellationToken = default);

    /// <summary>
    /// 删除分组。
    /// </summary>
    /// <param name="group">分组实体。</param>
    /// <param name="cancellationToken">取消标记。</param>
    Task RemoveAsync(DictionaryGroup group, CancellationToken cancellationToken = default);

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