using Kbx.Shared.ExternalData;
using Kbx.Shared.ExternalData.Generated;
using Xunit;
namespace Kbx.Tests.ExternalData;
public sealed class KbxExternalDataFreshnessPolicyTests
{
    [Fact] public void Strict_dataset_does_not_allow_stale_fallback()
    {
        var d=KbxExternalDataCatalog.All["dataset.kis.domestic-stock.current-price"];
        var received=new DateTimeOffset(2026,8,8,9,0,0,TimeSpan.Zero);
        var w=KbxExternalDataFreshnessPolicy.Window(d,received);
        Assert.Equal(w.FreshUntil,w.UsableUntil);
        Assert.Equal(KbxExternalDataState.Expired,KbxExternalDataFreshnessPolicy.Evaluate(d,received.AddSeconds(4),w.FreshUntil,w.UsableUntil));
    }
    [Fact] public void Stale_while_revalidate_is_explicit()
    {
        var d=KbxExternalDataCatalog.All["dataset.opendart.company-profile"];
        var received=new DateTimeOffset(2026,8,7,8,0,0,TimeSpan.Zero);
        var w=KbxExternalDataFreshnessPolicy.Window(d,received);
        Assert.Equal(KbxExternalDataState.Stale,KbxExternalDataFreshnessPolicy.Evaluate(d,received.AddHours(25),w.FreshUntil,w.UsableUntil));
    }
    [Fact] public void Krx_generic_dataset_requires_service_policy()
    {
        var d=KbxExternalDataCatalog.All["dataset.krx.approved-service"];
        Assert.Null(d.FreshForSeconds);
        Assert.Equal("provider-defined",d.FreshnessMode);
    }
}
