using System.Net;
using StellaOps.Feedser.Storage.Mongo.Documents;

namespace StellaOps.Feedser.Source.Common.Fetch;

/// <summary>
/// Outcome of fetching a raw document from an upstream source.
/// </summary>
public sealed record SourceFetchResult
{
    private SourceFetchResult(HttpStatusCode statusCode, DocumentRecord? document, bool notModified)
    {
        StatusCode = statusCode;
        Document = document;
        IsNotModified = notModified;
    }

    public HttpStatusCode StatusCode { get; }

    public DocumentRecord? Document { get; }

    public bool IsSuccess => Document is not null;

    public bool IsNotModified { get; }

    public static SourceFetchResult Success(DocumentRecord document, HttpStatusCode statusCode)
        => new(statusCode, document, notModified: false);

    public static SourceFetchResult NotModified(HttpStatusCode statusCode)
        => new(statusCode, null, notModified: true);

    public static SourceFetchResult Skipped(HttpStatusCode statusCode)
        => new(statusCode, null, notModified: false);
}
