import khan
import flight
import flight.operators as fo
import flight.operators.sku as sku

mixer = khan.client("mixer")

@mixer.implements("top_items_by_department", flight=True)
async def flight_path(
   client_id: int,
   department: str,
   diversity_coefficient: float = 0.5,
   limit:int = 10
):
   take_n = (
        sku.Kaleidoset(score_col="psale", rho=diversity_coefficient, n=limit)
        if diversity_coefficient > 0
        else fo.Limit(n=limit)
    )

    pipeline = (
        flight.Pipeline("top_items_by_department").initialize(
            include_candidates=[
                sku.AvailableSkusByChannel(channel="shop_your_look"),
                sku.Qualifications(),
                sku.ShopPSaleSource(score_col="psale"),
            ],
        )
        | sku.SkuAugment(columns=["style_variant_id", "department"])
        | fo.Equals(column="department", value=department)
        | fo.Sort(order_by="psale")
        | take_n
    )

    return await pipeline.execute(
        client_id=client_id,
        item_type="sku_id",
        debug=False,
        verbose=False,
    )