package com.jwipc.order.api.convert;

import com.jwipc.order.api.dto.CreateShortagePlanDTO;
import com.jwipc.order.entity.ShortageDetail;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;


@Mapper(componentModel = "spring")
public interface CreateShortagePlanConvert {
    @Mappings({
            @Mapping(target = "shortageVersion", source = "Z_VER"),
            @Mapping(target = "demandDate" ,expression="java(itDatum.Z_XQRQ != null && !itDatum.Z_XQRQ.trim().isEmpty() ? java.time.LocalDate.parse( itDatum.Z_XQRQ, java.time.format.DateTimeFormatter.ofPattern( \"yyyyMMdd\" )) :null)"),
            @Mapping(target = "factoryCode", source = "WERKS"),
            @Mapping(target = "workOrderNumber", source = "AUFNR"),
            @Mapping(target = "productCode", source = "MATNR"),
            @Mapping(target = "productLongName", source = "ZTDLINE"),
            @Mapping(target = "materialCode", source = "ZMATNR"),
            @Mapping(target = "materialLongName", source = "ZTDLINE2"),
            @Mapping(target = "materialGroup", source = "MATKL"),
            @Mapping(target = "demandQuantity", source = "BDMNG"),
            @Mapping(target = "materialGroupName", source = "WGBEZ"),
            @Mapping(target = "purchaseGroup", source = "EKGRP"),
            @Mapping(target = "currentQuantity", source = "Z_KC"),
            @Mapping(target = "undeliveredPurchaseQuantity", source = "Z_CGWJSL"),
            @Mapping(target = "shortageQuantity", source = "Z_QLSL"),
            @Mapping(target = "purchaseRequestQuantity", source = "Z_QGSL"),
            @Mapping(target = "qualityInspection", source = "Z_ZJKC"),
            @Mapping(target = "frozenInventory", source = "Z_DJKC"),
            @Mapping(target = "checkFrozenInventory", source = "ZIQCBLOCK"),
            @Mapping(target = "defectiveWarehouseQuantity", source = "Z_BLPKC"),
            @Mapping(target = "totalShortageQuantity", source = "Z_HJQLSL"),
            @Mapping(target = "successorMaterial", source = "NFMAT"),
            @Mapping(target = "successorMaterialUndeliveredQuantity", source = "Z_HJWJ"),
            @Mapping(target = "substituteMaterial1", source = "MAT_01"),
            @Mapping(target = "substituteMaterial1Inventory", source = "MNG_01"),
            @Mapping(target = "substituteMaterial2", source = "MAT_02"),
            @Mapping(target = "substituteMaterial2Inventory", source = "MNG_02"),
            @Mapping(target = "substituteMaterial3", source = "MAT_03"),
            @Mapping(target = "substituteMaterial3Inventory", source = "MNG_03"),
            @Mapping(target = "zyichng", source = "ZYICHANG"),
            @Mapping(target = "launchDate",expression="java(itDatum.ZSXRQ != null && !itDatum.ZSXRQ.trim().isEmpty() ? java.time.LocalDate.parse( itDatum.ZSXRQ, java.time.format.DateTimeFormatter.ofPattern( \"yyyyMMdd\" )) :null)")
    })
    ShortageDetail convert1(CreateShortagePlanDTO.ITData itDatum);
}
