using YLErp.Models;
namespace YLErp.Modules.SwapModule;
///
/// 利息腿 EOD 归档场景分派规格(纯函数集;表驱动单测见 InterestEodScenarioDispatchTest)。
/// 优先级链(承重业务语义,不能乱序):
/// ① hasSwap(手工互换) → 按事件流水重新生成,压制观察日自动结息
/// ② observationInterval(观察日) 存在 → 自动结息;同日有平仓 → autoSwap=true
/// ③ hasClose(纯平仓, 非观察日) → autoSwap=false
/// ④ 普通日 → 复制上一日终并计提当日新增
/// 注意:hasSwap/hasClose 是交易级标志(整笔合约当天有无事件),
/// observationInterval 是腿级(本条利息腿当天是否观察日)——粒度不同,分派依赖此区分。
/// 生产分派点:SwapEodPositionService.DealInterests(分派结构接线前为影子规格,见其分派处注释)。
///
public enum InterestEodScenario
{
ManualSwap, // ① 手工互换:压制观察日自动结息
AutoSettleWithClose, // ② 观察日 + 当日平仓 (autoSwap=true)
AutoSettle, // ② 观察日 + 当日无平仓
CloseOnly, // ③ 非观察日 + 当日平仓 (autoSwap=false)
RollForward, // ④ 普通日滚动
}
public static class InterestEodScenarioDispatch
{
/// 三分量布尔 → 场景(8 组合表驱动见 InterestEodScenarioDispatchTest)。
public static InterestEodScenario ResolveInterestScenario(bool hasInterval, bool hasSwap, bool hasClose)
{
if (hasSwap)
return InterestEodScenario.ManualSwap;
if (hasInterval)
return hasClose ? InterestEodScenario.AutoSettleWithClose : InterestEodScenario.AutoSettle;
if (hasClose)
return InterestEodScenario.CloseOnly;
return InterestEodScenario.RollForward;
}
///
/// 查找利息腿在指定结算日的观察日信息(SwapIntervalList 中 Date==settleDate 且 Settlement==1 的记录)。
/// 观察日即自动结息触发日;返回 null 表示当日非观察日。分派见 ResolveInterestScenario。
///
public static IntervalModel FindObservationInterval(swap_position interest, DateTime settleDate)
{
return interest.SwapIntervalList.FirstOrDefault(x => x.Date == settleDate && x.Settlement == 1);
}
}