import polars as pl


# step1 : 테이블 JOIN
def run(tb_sap_vbap, tb_sap_vbak, options, contexts):
    # 판매주문(salesOrder) 전체 Inner Join
    result = tb_sap_vbap.join(tb_sap_vbak, on="vbeln", how="inner").select(
        [
            pl.col("vbeln").alias("order_id"),
            pl.col("audat").alias("order_date"),
            pl.col("auart").alias("order_type"),
            pl.col("kunnr").alias("customer_id"),
            pl.col("posnr").alias("item_number"),
            pl.col("matnr").alias("material_id"),
            pl.col("arktx").alias("item_name"),
            pl.col("pstyv").alias("item_type"),
            pl.col("kwmeng").alias("quantity"),
            pl.col("vrkme").alias("sales_unit"),
            pl.col("netwr").alias("net_sales"),
        ]
    )

    return {"tb_sales_all": result}
