using System;
using YLErp.Derivatives.Interest;
namespace YLErp.Modules.SwapModule;
///
/// 把一个取价委托包装成 IIndexFixer。
///
/// 为什么不直接用 Fr007IndexFixer.Instance:SwapDealService.TryGetFloatRate 是
/// protected virtual,测试 override 它注入 stub。静态 Instance 直接调
/// EodPriceQueryService 会绕过这个接缝,导致测试失败。
/// 本类接受取价委托(SwapDealService 传入 this.TryGetFloatRate 的包装),
/// 既保留 virtual 接缝,又用上 IndexFixerBase,且无需访问 protected 成员。
///
internal sealed class SwapDealIndexFixer : IndexFixerBase, IIndexFixer
{
private readonly Func _tryGet;
internal SwapDealIndexFixer(Func tryGet)
=> _tryGet = tryGet;
public bool TryGetFixing(DateTime fixingDate, string underlyingCode, out decimal rate)
{
var (ok, r) = _tryGet(fixingDate, underlyingCode);
rate = Convert.ToDecimal(r);
return ok;
}
}