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.*;
import com.xunhong.erp.turbo.biz.domain.entity.Order;
import com.xunhong.erp.turbo.biz.infrastructure.entity.*;
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})
public interface OrderConvert {

	@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")
	Order toOrder(OrderDO orderDO);

	@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)
	OrderDO toOrderDO(OrderCreateCmd orderCreateCmd);

	@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 toOrderDO(@MappingTarget OrderDO orderDO, OrderUpdateCmd orderUpdateCmd);

	OrderStep1Cmd toOrderStep1Cmd(OrderCreateCmd orderCreateCmd);

	OrderStep2Cmd toOrderStep2Cmd(OrderCreateCmd orderCreateCmd);

	OrderStep3Cmd toOrderStep3Cmd(OrderCreateCmd orderCreateCmd);

	@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)
	OrderDO toOrderDO(OrderStep1Cmd orderStep1Cmd);

	@Mapping(target = "orderDO", 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 = "orderDO", 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 = "orderDO", 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 = "orderDO", 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);

	@Mapping(target = "file", ignore = true)
	@Mapping(target = "orderDO", ignore = true)
	@Mapping(target = "orderCostDOList", ignore = true)
	@Mapping(target = "orderShipItemDOList", ignore = true)
	@Mapping(target = "version", ignore = true)
	@Mapping(target = "updatedAt", ignore = true)
	@Mapping(target = "isDelete", ignore = true)
	@Mapping(target = "createdAt", ignore = true)
	@Mapping(target = "farmerInfo", ignore = true)
	OrderShipDO toOrderShipDO(OrderShip orderShip);

	List<OrderShip> toOrderShipList(List<OrderShipDO> orderShipDOList);

	@Mapping(target = "picUrl", source = "file.picUrl")
	@Mapping(target = "pdfUrl", source = "file.pdfUrl")
	@Mapping(target = "orderShipItemList", source = "orderShipItemDOList")
	OrderShip toOrderShip(OrderShipDO orderShipDO);

	List<OrderShipItem> toOrderShipItemList(List<OrderShipItemDO> orderShipItemDOList);

	OrderShipItem toOrderShipItem(OrderShipItemDO orderShipItemDO);

	@Mapping(target = "version", ignore = true)
	@Mapping(target = "updatedAt", ignore = true)
	@Mapping(target = "isDelete", ignore = true)
	@Mapping(target = "createdAt", ignore = true)
	OrderShipItemDO toOrderShipItemDO(OrderShipItem orderShipItem);
}

