package com.xunhong.erp.turbo.biz.infrastructure.convert;

import com.xunhong.erp.turbo.api.biz.dto.cmd.*;
import com.xunhong.erp.turbo.api.biz.dto.common.OrderCost;
import com.xunhong.erp.turbo.api.biz.dto.common.OrderRebate;
import com.xunhong.erp.turbo.api.biz.dto.common.OrderSupplier;
import com.xunhong.erp.turbo.biz.domain.entity.PurchaseOrder;
import com.xunhong.erp.turbo.biz.infrastructure.entity.OrderCostDO;
import com.xunhong.erp.turbo.biz.infrastructure.entity.OrderRebateDO;
import com.xunhong.erp.turbo.biz.infrastructure.entity.OrderSupplierDO;
import com.xunhong.erp.turbo.biz.infrastructure.entity.PurchaseOrderDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.NullValueCheckStrategy;

import java.util.List;

/**
 * @author shenyifei
 */
@Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, uses = {OrderVehicleConvert.class, OrderCostConvert.class, OrderPackageConvert.class, OrderDealerConvert.class, OrderRebateConvert.class, OrderCompanyConvert.class, OrderPackageConvert.class, OrderShipItemConvert.class, OrderShipConvert.class})
public interface PurchaseOrderConvert {

	@Mapping(target = "orderShipList", source = "orderShipDOList")
	@Mapping(target = "orderPackageList", source = "orderPackageDOList")
	@Mapping(target = "orderRebate", source = "orderRebateDO")
	@Mapping(target = "orderCompany", source = "orderCompanyDO")
	@Mapping(target = "orderDealer", source = "orderDealerDO")
	@Mapping(target = "orderCostList", source = "orderCostDOList")
	@Mapping(target = "orderCostItemList", source = "orderCostItemDOList")
	@Mapping(target = "orderSupplierList", source = "orderSupplierDOList")
	@Mapping(target = "orderVehicle", source = "orderVehicleDO")
	PurchaseOrder toPurchaseOrder(PurchaseOrderDO purchaseOrderDO);

	@Mapping(target = "orderShipDOList", ignore = true)
	@Mapping(target = "orderCostItemDOList", ignore = true)
	@Mapping(target = "auditState", ignore = true)
	@Mapping(target = "orderPackageDOList", ignore = true)
	@Mapping(target = "pricingMethod", ignore = true)
	@Mapping(target = "orderRebateDO", ignore = true)
	@Mapping(target = "orderCompanyDO", ignore = true)
	@Mapping(target = "orderDealerDO", ignore = true)
	@Mapping(target = "orderCostDOList", ignore = true)
	@Mapping(target = "orderSn", ignore = true)
	@Mapping(target = "orderVehicleDO", ignore = true)
	@Mapping(target = "orderSupplierDOList", ignore = true)
	@Mapping(target = "state", ignore = true)
	@Mapping(target = "orderId", ignore = true)
	@Mapping(target = "version", ignore = true)
	@Mapping(target = "updatedAt", ignore = true)
	@Mapping(target = "isDelete", ignore = true)
	@Mapping(target = "createdAt", ignore = true)
	PurchaseOrderDO toPurchaseOrderDO(PurchaseOrderCreateCmd purchaseOrderCreateCmd);

	@Mapping(target = "orderShipDOList", ignore = true)
	@Mapping(target = "orderCostItemDOList", ignore = true)
	@Mapping(target = "auditState", ignore = true)
	@Mapping(target = "orderPackageDOList", ignore = true)
	@Mapping(target = "pricingMethod", ignore = true)
	@Mapping(target = "orderRebateDO", ignore = true)
	@Mapping(target = "orderCompanyDO", ignore = true)
	@Mapping(target = "orderDealerDO", ignore = true)
	@Mapping(target = "orderCostDOList", ignore = true)
	@Mapping(target = "orderVehicleDO", ignore = true)
	@Mapping(target = "orderSupplierDOList", ignore = true)
	@Mapping(target = "orderSn", ignore = true)
	@Mapping(target = "state", ignore = true)
	@Mapping(target = "createdByName", ignore = true)
	@Mapping(target = "version", ignore = true)
	@Mapping(target = "updatedAt", ignore = true)
	@Mapping(target = "isDelete", ignore = true)
	@Mapping(target = "createdAt", ignore = true)
	void toPurchaseOrderDO(@MappingTarget PurchaseOrderDO purchaseOrderDO, PurchaseOrderUpdateCmd purchaseOrderUpdateCmd);

	PurchaseOrderStep1Cmd toPurchaseOrderStep1Cmd(PurchaseOrderCreateCmd purchaseOrderCreateCmd);

	PurchaseOrderStep2Cmd toPurchaseOrderStep2Cmd(PurchaseOrderCreateCmd purchaseOrderCreateCmd);

	PurchaseOrderStep3Cmd toPurchaseOrderStep3Cmd(PurchaseOrderCreateCmd purchaseOrderCreateCmd);

	@Mapping(target = "orderShipDOList", ignore = true)
	@Mapping(target = "orderCostItemDOList", ignore = true)
	@Mapping(target = "auditState", ignore = true)
	@Mapping(target = "foreman", ignore = true)
	@Mapping(target = "orderPackageDOList", ignore = true)
	@Mapping(target = "originPrincipal", source = "createdByName")
	@Mapping(target = "version", ignore = true)
	@Mapping(target = "updatedAt", ignore = true)
	@Mapping(target = "state", ignore = true)
	@Mapping(target = "remark", ignore = true)
	@Mapping(target = "pricingMethod", ignore = true)
	@Mapping(target = "orderVehicleDO", ignore = true)
	@Mapping(target = "orderSupplierDOList", ignore = true)
	@Mapping(target = "orderSn", ignore = true)
	@Mapping(target = "orderRebateDO", ignore = true)
	@Mapping(target = "orderDealerDO", ignore = true)
	@Mapping(target = "orderCostDOList", ignore = true)
	@Mapping(target = "orderCompanyDO", ignore = true)
	@Mapping(target = "isDelete", ignore = true)
	@Mapping(target = "createdAt", ignore = true)
	PurchaseOrderDO toPurchaseOrderDO(PurchaseOrderStep1Cmd purchaseOrderStep1Cmd);

	@Mapping(target = "purchaseOrderDO", ignore = true)
	@Mapping(target = "orderCompanyDO", ignore = true)
	@Mapping(target = "orderPackageDOList", source = "orderPackageList")
	@Mapping(target = "orderSupplierId", ignore = true)
	@Mapping(target = "version", ignore = true)
	@Mapping(target = "updatedAt", ignore = true)
	@Mapping(target = "isDelete", ignore = true)
	@Mapping(target = "createdAt", ignore = true)
	OrderSupplierDO toOrderSupplierDO(OrderSupplier orderSupplier);

	List<OrderSupplierDO> toOrderSupplierDOList(List<OrderSupplier> orderSupplierList);

	List<OrderSupplier> toOrderSupplierList(List<OrderSupplierDO> orderSupplierDOList);

	@Mapping(target = "selected", ignore = true)
	@Mapping(target = "orderCompany", source = "orderCompanyDO")
	@Mapping(target = "createdByName", ignore = true)
	@Mapping(target = "createdBy", ignore = true)
	@Mapping(target = "orderPackageList", source = "orderPackageDOList")
	OrderSupplier toOrderSupplier(OrderSupplierDO orderSupplierDO);

	@Mapping(target = "purchaseOrderDO", ignore = true)
	@Mapping(target = "pricingMethod", ignore = true)
	@Mapping(target = "poState", ignore = true)
	@Mapping(target = "packageUsage", ignore = true)
	@Mapping(target = "orderCompanyDO", ignore = true)
	@Mapping(target = "costTemplate", ignore = true)
	@Mapping(target = "costIds", ignore = true)
	@Mapping(target = "wechatQr", ignore = true)
	@Mapping(target = "totalWeightImg", ignore = true)
	@Mapping(target = "totalWeight", ignore = true)
	@Mapping(target = "supplierId", ignore = true)
	@Mapping(target = "salePrice", ignore = true)
	@Mapping(target = "purchasePrice", ignore = true)
	@Mapping(target = "productName", ignore = true)
	@Mapping(target = "productId", ignore = true)
	@Mapping(target = "phone", ignore = true)
	@Mapping(target = "orderId", ignore = true)
	@Mapping(target = "netWeight", ignore = true)
	@Mapping(target = "name", ignore = true)
	@Mapping(target = "isPaper", ignore = true)
	@Mapping(target = "isLast", ignore = true)
	@Mapping(target = "invoiceAmount", ignore = true)
	@Mapping(target = "idCard", ignore = true)
	@Mapping(target = "grossWeight", ignore = true)
	@Mapping(target = "emptyWeightImg", ignore = true)
	@Mapping(target = "emptyWeight", ignore = true)
	@Mapping(target = "createdAt", ignore = true)
	@Mapping(target = "bankCard", ignore = true)
	@Mapping(target = "version", ignore = true)
	@Mapping(target = "updatedAt", ignore = true)
	@Mapping(target = "orderPackageDOList", ignore = true)
	@Mapping(target = "isDelete", ignore = true)
	@Mapping(target = "isDepositPaid", ignore = true)
	@Mapping(target = "depositAmount", ignore = true)
	void toOrderSupplierDO(@MappingTarget OrderSupplierDO orderSupplierDO, OrderSupplierUpdateCmd orderSupplierUpdateCmd);

	@Mapping(target = "purchaseOrderDO", ignore = true)
	@Mapping(target = "poState", ignore = true)
	@Mapping(target = "orderCompanyDO", ignore = true)
	@Mapping(target = "orderCostId", ignore = true)
	@Mapping(target = "version", ignore = true)
	@Mapping(target = "updatedAt", ignore = true)
	@Mapping(target = "isDelete", ignore = true)
	@Mapping(target = "createdAt", ignore = true)
	OrderCostDO toOrderCostDO(OrderCost orderCost);

	List<OrderCostDO> toOrderCostDOList(List<OrderCost> orderCostList);

	List<OrderCost> toOrderCostList(List<OrderCostDO> orderCostDOList);

	@Mapping(target = "selected", ignore = true)
	@Mapping(target = "createdByName", ignore = true)
	@Mapping(target = "createdBy", ignore = true)
	OrderCost toOrderCost(OrderCostDO orderCostDO);

	@Mapping(target = "purchaseOrderDO", ignore = true)
	@Mapping(target = "poState", ignore = true)
	@Mapping(target = "orderCompanyDO", ignore = true)
	@Mapping(target = "version", ignore = true)
	@Mapping(target = "updatedAt", ignore = true)
	@Mapping(target = "isDelete", ignore = true)
	@Mapping(target = "createdAt", ignore = true)
	OrderRebateDO toOrderRebateDO(OrderRebate orderRebate);

	OrderRebate toOrderRebate(OrderRebateDO orderRebateDO);
}

