package com.neusoft.smart.pos.payorder.service;

import com.neusoft.smart.pos.constants.DictionaryConstant;
import com.neusoft.smart.pos.dto.order.request.*;
import com.neusoft.smart.pos.dto.order.response.*;
import com.neusoft.smart.pos.dto.payorder.request.PostCreatePayRefundOrderRequest;
import com.neusoft.smart.pos.dto.payorder.response.PostPayRefundOrderResponse;
import com.neusoft.smart.pos.framework.utils.IdGenerateUtils;
import com.neusoft.smart.pos.payorder.persistent.domain.PayRefundOrder;
import com.neusoft.smart.pos.payorder.repository.PayRefundOrderRepository;
import lombok.val;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("payRefundOrderService")
public class PayRefundOrderService {
    @Autowired
    private PayRefundOrderRepository payRefundOrderRepository;

    public PostPayRefundOrderResponse createPayRefundOrder(PostCreatePayRefundOrderRequest createPayRefundOrderRequest) {
        PayRefundOrder payRefundOrder = new PayRefundOrder();
        BeanUtils.copyProperties(createPayRefundOrderRequest, payRefundOrder);
        payRefundOrder.setPayRefundOrderNumber(IdGenerateUtils.generateTradeId());
        payRefundOrderRepository.createPayRefundOrder(payRefundOrder);
        val postPayRefundOrderResponse = new com.neusoft.smart.pos.dto.payorder.response.PostPayRefundOrderResponse();
        BeanUtils.copyProperties(payRefundOrder, postPayRefundOrderResponse);
        return postPayRefundOrderResponse;
    }

    public PostRefundOrderResponse saveRefundOrder(PostSaveRefundOrderRequest saveRefundOrderRequest) {
        return null;
    }

    public boolean canclePayRefundOrder(String payRefundNum) {


        boolean result = payRefundOrderRepository.updatePayRefundOrderStatus(payRefundNum, DictionaryConstant.PAY_REFUND_STATUS__YQX.getCode());
        return result;
    }

    public boolean setRefundOrderStatus(String payRefundNum, String refundStatus) {
        boolean result = payRefundOrderRepository.updatePayRefundOrderStatus(payRefundNum, refundStatus);
        return result;
    }

    public List<PayRefundOrder> getPayRefundOrderInfoByOrderNumber(String refundNumber) {
        List<PayRefundOrder> orderRefundDetails = payRefundOrderRepository.queryPayRefundOrder(refundNumber);
        return orderRefundDetails;
    }

    public PostDoRefundOrderResponse doRefund(PostDoPayOrderRequest doPayOrderRequest) {
        return null;
    }

    public PayRefundOrder getPayRefundOrder(String payRefundOrderId) {
        return payRefundOrderRepository.getPayRefundOrder(payRefundOrderId);
    }

    public boolean updatePayRefundOrder(PayRefundOrder payRefundOrder) {
        return payRefundOrderRepository.updatePayRefundOrder(payRefundOrder.getOuterOrderNumber(),payRefundOrder);
    }

    public boolean updatePayRefundOrderStatus(String outerOrderNumber, String status) {
        PayRefundOrder payRefundOrder = new PayRefundOrder();
        payRefundOrder.setRefundStatus(status);
        return payRefundOrderRepository.updatePayRefundOrderStatus(payRefundOrder,outerOrderNumber);
    }

    public boolean updatePayRefundOrderStatusById(String payRefundOrderNumber, String status) {
        PayRefundOrder payRefundOrder = new PayRefundOrder();
        payRefundOrder.setRefundStatus(status);
        return payRefundOrderRepository.updatePayRefundOrderStatusById(payRefundOrder,payRefundOrderNumber);
    }
}
