using System.Text.Json;

namespace Kbx.Shared.ExternalData;

public enum KbxExternalDataState { Fresh, Stale, Expired, Unavailable }
public enum KbxExternalDataFreshnessMode { Strict, StaleWhileRevalidate, ProviderDefined }

public sealed record KbxExternalDataProvenance(
    string DatasetId,
    string ProviderId,
    string ProviderOperationId,
    string SourceLabel,
    KbxExternalDataState State,
    DateTimeOffset? ProviderObservedAt,
    DateTimeOffset RequestedAt,
    DateTimeOffset ReceivedAt,
    DateTimeOffset IngestedAt,
    DateTimeOffset? FreshUntil,
    DateTimeOffset? UsableUntil,
    string PayloadSha256,
    string NormalizerVersion,
    bool CacheHit,
    bool RefreshInProgress = false,
    string? Warning = null);

public sealed record KbxExternalDataEnvelope<T>(T? Data, KbxExternalDataProvenance Provenance);

public sealed record KbxExternalDataCacheEntry(
    Guid TenantId,
    string DatasetId,
    string ProviderId,
    string CacheKey,
    JsonDocument RequestDescriptor,
    JsonDocument NormalizedData,
    DateTimeOffset? ProviderObservedAt,
    DateTimeOffset RequestedAt,
    DateTimeOffset ReceivedAt,
    DateTimeOffset IngestedAt,
    DateTimeOffset? FreshUntil,
    DateTimeOffset? UsableUntil,
    string PayloadSha256,
    string NormalizerVersion,
    string State,
    string CorrelationId);

public sealed record KbxCompanyProfileSnapshot(string CorpCode, string CorpName, string? StockCode, string? BusinessNumber);
public sealed record KbxDisclosureSummarySnapshot(string ReceiptNo, string CorpCode, string CorpName, string ReportName, string ReceiptDate);
public sealed record KbxMarketPriceSnapshot(string MarketDivisionCode, string StockCode, decimal CurrentPrice);
