
package com.yami.shop.platform.controller.smqjh;

import com.alibaba.fastjson2.JSONObject;
import com.yami.shop.bean.vo.xsb.RefundOrderPushVo;
import com.yami.shop.common.bean.smqjh.OrderRefundCancelVo;
import com.yami.shop.common.bean.smqjh.OrderRefundExpressParamVo;
import com.yami.shop.common.util.R;
import com.yami.shop.service.xsb.XSBRefundOrderService;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.UUID;

/**
 * 星闪豹数据同步问题
 *
 * @author FBJ
 * @version 1.0.0
 * @since 2025-12-15
 */
@RestController
@RequestMapping("/platform/xsb/refund")
@AllArgsConstructor
@Log4j2
public class XSBRefundOrderController {


    private final XSBRefundOrderService xsbRefundOrderService;


    /**
     * 同步退款订单数据
     */
    @PostMapping("/applyAfterSales")
    public R<String> applyAfterSales(@RequestBody RefundOrderPushVo refundOrderPushVo) {
        String string = UUID.randomUUID().toString();
        log.info("【"+string+"】"+"接收第三方退款订单推送{}",refundOrderPushVo);
        return  xsbRefundOrderService.applyAfterSales(refundOrderPushVo,string);
    }

    /**
     * 修改物流信息
     */
    @PostMapping("/updateExpress")
    public R<String> updateExpress(@RequestBody OrderRefundExpressParamVo orderRefundExpressParamVo) {
        String string = UUID.randomUUID().toString();
        log.info("【"+string+"】"+"接收第三方退款订单修改物流信息推送{}", JSONObject.toJSONString(orderRefundExpressParamVo));
        return  xsbRefundOrderService.updateExpress(orderRefundExpressParamVo);
    }

    /**
     * 取消退款订单申请
     */
    @PostMapping("/cancel")
    public R<String> cancel(@RequestBody OrderRefundCancelVo orderRefundCancelVo) {
        String string = UUID.randomUUID().toString();
        log.info("【"+string+"】"+"接收第三方取消退款订单申请推送{}", JSONObject.toJSONString(orderRefundCancelVo));
        return  xsbRefundOrderService.cancel(orderRefundCancelVo,string);
    }

    /**
     * 变更海博订单状态（OMS恢复订单状态时调用）
     */
    @PostMapping("/changeHbOrderStatus")
    public R<String> changeHbOrderStatus(@RequestBody Map<String, Object> params) {
        String orderNumber = (String) params.get("orderNumber");
        Integer status = (Integer) params.get("status");
        log.info("接收变更海博订单状态请求, orderNumber: {}, status: {}", orderNumber, status);
        return xsbRefundOrderService.changeHbOrderStatus(orderNumber, status);
    }

    /**
     * 变更海博退款订单状态
     */
    @PostMapping("/changeHbRefundOrderStatus")
    public R<String> changeHbRefundOrderStatus(@RequestBody Map<String, Object> params) {
        String refundSn = (String) params.get("refundSn");
        Integer status = (Integer) params.get("status");
        log.info("接收变更海博退款订单状态请求, refundSn: {}, status: {}", refundSn, status);
        return xsbRefundOrderService.changeHbRefundOrderStatus(refundSn, status);
    }

}
