package com.gic.haoban.manage.service.service.out.impl.contact;

import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil;
import com.gic.haoban.manage.api.dto.contact.ContactLogDTO;
import com.gic.haoban.manage.api.qdto.contact.ContactOrderQDTO;
import com.gic.haoban.manage.api.service.contact.ContactLogApiService;
import com.gic.haoban.manage.api.service.contact.ContactOrderApiService;
import com.gic.haoban.manage.service.entity.contact.TabContactLog;
import com.gic.haoban.manage.service.service.contact.ContactLogService;
import com.gic.haoban.manage.service.service.contact.ContactOrderService;
import com.gic.order.api.dto.resp.OrderInfoResp;
import com.gic.order.api.service.member.MemberOrderReadApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by wangzubo on 2022/11/1.
 */
@Service("contactOrderApiService")
public class ContactOrderApiServiceImpl implements ContactOrderApiService {

    @Autowired
    private ContactOrderService contactOrderService;
    @Autowired
    private MemberOrderReadApiService memberOrderReadApiService;

    @Override
    public ServiceResponse<Void> saveContactOrder(ContactOrderQDTO contactOrderQDTO) {
        String enterpriseId = contactOrderQDTO.getEnterpriseId();
        String memberId = contactOrderQDTO.getMemberId();
        String orderId = contactOrderQDTO.getOrderId();
        boolean isOnlineOrder = contactOrderQDTO.isOnlineOrder();
        ServiceResponse<OrderInfoResp> serviceResponse =
                memberOrderReadApiService.getOrder(enterpriseId, memberId, orderId, isOnlineOrder);
        if (!serviceResponse.isSuccess() || serviceResponse.getResult() == null) {
            return ServiceResponse.success();
        }
        OrderInfoResp result = serviceResponse.getResult();
        contactOrderService.saveContactOrder(result);
        return ServiceResponse.success();
    }

}
