from pot_libs.sanic_api import summary
from unify_api.modules.load_analysis.components.load_forecast_cps import (
    ForecastReq, ForecastResp,
)
from unify_api.modules.load_analysis.service.load_forecast_service import \
    load_forecast_srv
from unify_api.utils.time_format import time_pick_transf_new


@summary("负荷预测")
async def post_load_forecast(req, body: ForecastReq) -> ForecastResp:
    """负荷预测"""
    # 1.获取参数
    cid = body.cid
    start = body.start
    end = body.end
    # 管理版本多个工厂的情况, 兼容能力最强的参数cids， 保留旧有的cid:
    cids = body.cids
    terms = cids if cids else [cid]
    # 获取时间差
    interval, slots = time_pick_transf_new(start, end)
    return await load_forecast_srv(terms, start, end, interval, slots)
