using Microsoft.SharePoint.Client;
using SharepointToolbox.Core.Models;

namespace SharepointToolbox.Services;

public interface IStorageService
{
    /// <summary>
    /// Collects storage metrics for a site, capturing every storage source
    /// SharePoint reports (visible + hidden libraries, Preservation Hold,
    /// list attachments, recycle bin, and optionally subsites). Each
    /// <see cref="StorageNode"/> carries a <see cref="StorageNodeKind"/> so
    /// callers can filter what appears in the report.
    /// </summary>
    Task<IReadOnlyList<StorageNode>> CollectStorageAsync(
        ClientContext ctx,
        StorageScanOptions options,
        IProgress<OperationProgress> progress,
        CancellationToken ct);

    /// <summary>
    /// Enumerates files across all non-hidden document libraries in the site
    /// and aggregates storage consumption grouped by file extension.
    /// </summary>
    Task<IReadOnlyList<FileTypeMetric>> CollectFileTypeMetricsAsync(
        ClientContext ctx,
        IProgress<OperationProgress> progress,
        CancellationToken ct);

    /// <summary>
    /// Backfills StorageNodes that have zero TotalFileCount/TotalSizeBytes
    /// by enumerating files per library via CamlQuery. Only re-runs against
    /// document-library kinds (Library, HiddenLibrary, PreservationHold).
    /// </summary>
    Task BackfillZeroNodesAsync(
        ClientContext ctx,
        IReadOnlyList<StorageNode> nodes,
        IProgress<OperationProgress> progress,
        CancellationToken ct);

    /// <summary>
    /// Returns the SharePoint-reported total storage usage for the site
    /// (Site.Usage.Storage). This includes everything that counts toward
    /// the site quota — recycle bin, version history, hidden libraries,
    /// list attachments — and serves as the ground-truth reference total.
    /// Returns 0 if the call is denied or the property is unavailable.
    /// </summary>
    Task<long> GetSiteUsageStorageBytesAsync(
        ClientContext ctx,
        IProgress<OperationProgress> progress,
        CancellationToken ct);
}
