package com.yami.shop.api.controller;

import com.yami.shop.bean.app.param.OrderRefundParam;
import com.yami.shop.bean.enums.OrderStatus;
import com.yami.shop.bean.model.Order;
import com.yami.shop.delivery.comment.api.paotui.model.request.NoticeModel;
import com.yami.shop.service.OrderRefundService;
import com.yami.shop.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/delivery/notice")
@Api(tags = "物流通知接口")
@AllArgsConstructor
public class DeliveryNoticeController {
    @Autowired
    private OrderRefundService orderRefundService;

    @Autowired
    private OrderService orderService;


    @GetMapping("/put")
    @ApiOperation(value = "查看物流列表", notes = "查看物流列表")
    public ResponseEntity<String> checkDelivery(@RequestBody NoticeModel noticeModel) {
        Integer status = Integer.valueOf(noticeModel.getStatus());
        if(status==70 || status== 60){
            OrderRefundParam orderRefundParam = new OrderRefundParam();
            orderRefundParam.setRefundType(1);
            orderRefundParam.setOrderNumber(noticeModel.getOrigin_id());
            orderRefundParam.setBuyerReason("超时无人接单，自动取消");
            orderRefundParam.setIsReceiver(false);
            orderRefundService.overTimeRefundOrder(orderRefundParam);
        }else if(status==50){
            Order orderByOrderNumber = orderService.getOrderByOrderNumber(noticeModel.getOrigin_id());
            if(orderByOrderNumber!=null){
                orderByOrderNumber.setHbOrderStatus(OrderStatus.EVALUATE.value());
                orderService.updateById(orderByOrderNumber);
            }
        }
        return ResponseEntity.ok("回调消息");
    }


}
