namespace SharepointToolbox.Core.Models;

public class BulkItemResult<T>
{
    public T Item { get; }
    public bool IsSuccess { get; }
    public string? ErrorMessage { get; }
    public DateTime Timestamp { get; }

    private BulkItemResult(T item, bool success, string? error)
    {
        Item = item;
        IsSuccess = success;
        ErrorMessage = error;
        Timestamp = DateTime.UtcNow;
    }

    public static BulkItemResult<T> Success(T item) => new(item, true, null);
    public static BulkItemResult<T> Failed(T item, string error) => new(item, false, error);
}

public class BulkOperationSummary<T>
{
    public IReadOnlyList<BulkItemResult<T>> Results { get; }
    public int TotalCount => Results.Count;
    public int SuccessCount => Results.Count(r => r.IsSuccess);
    public int FailedCount => Results.Count(r => !r.IsSuccess);
    public bool HasFailures => FailedCount > 0;
    public IReadOnlyList<BulkItemResult<T>> FailedItems => Results.Where(r => !r.IsSuccess).ToList();

    public BulkOperationSummary(IReadOnlyList<BulkItemResult<T>> results)
    {
        Results = results;
    }
}
