package com.prolog.upcloud.base.wh.operate.convert;

import com.prolog.upcloud.base.inventory.vo.InvStockMove;
import com.prolog.upcloud.base.inventory.vo.InvStockMoveDetail;
import com.prolog.upcloud.base.wh.operate.model.WmsMoveD;
import com.prolog.upcloud.base.wh.operate.model.WmsMoveH;
import com.prolog.upcloud.base.wh.operate.model.WmsStereoD;
import com.prolog.upcloud.base.wh.operate.model.WmsStereoH;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.math.BigDecimal;

@Mapper(componentModel = "spring")
public interface StockConvert {

    @Mapping(target = "billId", source = "d.moveHeaderId")
    @Mapping(target = "warehouseId", source = "h.warehouseId")
    @Mapping(target = "lineBillId", source = "d.moveLineId")
    @Mapping(target = "details", expression = "java(java.util.Collections.singletonList(generateStockMoveInfo(d)))")
    InvStockMove generateStockMove(WmsMoveD d, WmsMoveH h);

    @Mapping(target = "batchId", source = "d.batchId")
    @Mapping(target = "inLocatorId", source = "d.inLocatorId")
    @Mapping(target = "inContainerCode", source = "d.inContainerCode")
    @Mapping(target = "inGoodsCaseCode", source = "d.inGoodsCaseCode")
    @Mapping(target = "comments", source = "d.comments")
    @Mapping(target = "inStockStatus", source = "d.inStockStatus")
    @Mapping(target = "outLocatorId", source = "d.outLocatorId")
    @Mapping(target = "quantity", source = "d.pieceQuantity")
    @Mapping(target = "outContainerCode", source = "d.outContainerCode")
    @Mapping(target = "outGoodsCaseCode", source = "d.outGoodsCaseCode")
    @Mapping(target = "outStockStatus", source = "d.outStockStatus")
    @Mapping(target = "inStockSubStatus", expression = "java(com.prolog.upcloud.base.inventory.enums.StockSubStatusEnum.NORMAL.getCode())")
    @Mapping(target = "outStockSubStatus", expression = "java(com.prolog.upcloud.base.inventory.enums.StockSubStatusEnum.NORMAL.getCode())")
    InvStockMoveDetail generateStockMoveInfo(WmsMoveD d);


    @Mapping(target = "billId", source = "h.headerId")
    @Mapping(target = "warehouseId", source = "h.warehouseId")
    @Mapping(target = "lineBillId", source = "d.detailId")
    //@Mapping(target = "biteFlag", source = "d.detailId")
    @Mapping(target = "details", expression = "java(java.util.Collections.singletonList(generateStockStereoInfo(d,h,otherStereoH,qty)))")
    InvStockMove generateStockStereo(WmsStereoD d, WmsStereoH h, WmsStereoH otherStereoH, BigDecimal qty);

    @Mapping(target = "batchId", source = "d.batchId")
    @Mapping(target = "inLocatorId", source = "otherStereoH.locatorId")
    @Mapping(target = "inContainerCode", source = "d.toContainerCode")
    //@Mapping(target = "inGoodsCaseCode", source = "d.inGoodsCaseCode")
    //@Mapping(target = "comments", source = "d.comments")
    @Mapping(target = "inStockStatus", source = "d.stockStatus")
    @Mapping(target = "outLocatorId", source = "h.locatorId")
    @Mapping(target = "quantity", source = "qty")
    @Mapping(target = "outContainerCode", source = "h.containerCode")
    //@Mapping(target = "outGoodsCaseCode", source = "d.outGoodsCaseCode")
    @Mapping(target = "outStockStatus", source = "d.stockStatus")
        //@Mapping(target = "inStockSubStatus", source = "d.inStockSubStatus")
    InvStockMoveDetail generateStockStereoInfo(WmsStereoD d, WmsStereoH h, WmsStereoH otherStereoH, BigDecimal qty);

}