package com.hys.app.converter.erp;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hys.app.framework.database.WebPage;
import com.hys.app.model.erp.dos.*;
import com.hys.app.model.erp.dto.OrderDTO;
import com.hys.app.model.erp.enums.OrderStatusEnum;
import com.hys.app.model.erp.enums.OrderTypeEnum;
import com.hys.app.model.erp.vo.OrderExcelVO;
import com.hys.app.model.erp.vo.OrderItemVO;
import com.hys.app.model.erp.vo.OrderVO;
import com.hys.app.service.kuaidiniao.entity.PreOrderModel;
import com.hys.app.service.kuaidiniao.entity.PreOrderModelDTO;
import com.hys.app.service.kuaidiniao.entity.ReceiverSender;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import org.mapstruct.MappingTarget;

import java.util.List;
import java.util.Map;

/**
 * 订单 Converter
 *
 * @author 张崧
 * 2024-01-24 15:58:31
 */
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface OrderConverter {

    OrderDO convert(OrderDTO orderDTO);

    List<OrderVO> convertList(List<OrderDO> list);

    WebPage<OrderVO> convertPage(WebPage<OrderDO> webPage);

    default OrderStatusEnum convertAuditStatus(Boolean isPass, OrderTypeEnum type) {
        if (isPass) {
            return type == OrderTypeEnum.TO_C ? OrderStatusEnum.COMPLETE : OrderStatusEnum.WAIT_WAREHOUSE_OUT;
        } else {
            return OrderStatusEnum.AUDIT_REJECT;
        }
    }

    @Mapping(target = "aDo.receiverProvinceName", source = "receiver.provinceName")
    @Mapping(target = "aDo.receiverCityName", source = "receiver.cityName")
    @Mapping(target = "aDo.receiverAreaName", source = "receiver.areaName")
    @Mapping(target = "aDo.receiverAddress", source = "receiver.address")
    @Mapping(target = "aDo.receiverName", source = "receiver.name")
    @Mapping(target = "aDo.receiverPhone", source = "receiver.phone")
    @Mapping(target = "aDo.receiverMobile", source = "receiver.mobile")
    @Mapping(target = "aDo.receiverLatitude", source = "receiver.latitude")
    @Mapping(target = "aDo.receiverLongitude", source = "receiver.longitude")
    @Mapping(target = "aDo.senderProvinceName", source = "sender.provinceName")
    @Mapping(target = "aDo.senderCityName", source = "sender.cityName")
    @Mapping(target = "aDo.senderAreaName", source = "sender.areaName")
    @Mapping(target = "aDo.senderAddress", source = "sender.address")
    @Mapping(target = "aDo.senderName", source = "sender.name")
    @Mapping(target = "aDo.senderMobile", source = "sender.mobile")
    @Mapping(target = "aDo.senderPhone", source = "sender.phone")
    @Mapping(target = "aDo.senderLatitude", source = "sender.latitude")
    @Mapping(target = "aDo.senderLongitude", source = "sender.longitude")
    @Mapping(target = "aDo.deleted", ignore = true)
    void copyProperties(@MappingTarget OrderSendDO aDo, PreOrderModelDTO preOrderModel, ReceiverSender receiver, ReceiverSender sender);



    @Mapping(target = "preOrderModel.sender.longitude", source = "aDo.senderLongitude")
    @Mapping(target = "preOrderModel.sender.latitude", source = "aDo.senderLatitude")
    @Mapping(target = "preOrderModel.sender.phone", source = "aDo.senderPhone")
    @Mapping(target = "preOrderModel.sender.mobile", source = "aDo.senderMobile")
    @Mapping(target = "preOrderModel.sender.name", source = "aDo.senderName")
    @Mapping(target = "preOrderModel.sender.address", source = "aDo.senderAddress")
    @Mapping(target = "preOrderModel.sender.areaName", source = "aDo.senderAreaName")
    @Mapping(target = "preOrderModel.sender.cityName", source = "aDo.senderCityName")
    @Mapping(target = "preOrderModel.sender.provinceName", source = "aDo.senderProvinceName")
    @Mapping(target = "preOrderModel.receiver.longitude", source = "aDo.receiverLongitude")
    @Mapping(target = "preOrderModel.receiver.latitude", source = "aDo.receiverLatitude")
    @Mapping(target = "preOrderModel.receiver.mobile", source = "aDo.receiverMobile")
    @Mapping(target = "preOrderModel.receiver.phone", source = "aDo.receiverPhone")
    @Mapping(target = "preOrderModel.receiver.name", source = "aDo.receiverName")
    @Mapping(target = "preOrderModel.receiver.address", source = "aDo.receiverAddress")
    @Mapping(target = "preOrderModel.receiver.areaName", source = "aDo.receiverAreaName")
    @Mapping(target = "preOrderModel.receiver.cityName", source = "aDo.receiverCityName")
    @Mapping(target = "preOrderModel.receiver.provinceName", source = "aDo.receiverProvinceName")
    void copyProperties(@MappingTarget PreOrderModel preOrderModel, OrderSendDO aDo);
}

