package com.yiqi.admin.controller.core;

import com.alibaba.fastjson.JSON;
import com.yiqi.common.constant.UrlConstants;
import com.yiqi.common.enums.WxEventType;
import com.yiqi.common.utils.EnumUtils;
import com.yiqi.core.domain.dto.WxNotifyDTO;
import com.yiqi.order.service.IThirdDeliveryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author xiaohei
 * @date 2024/1/25
 */
@RestController
@RequestMapping(value = UrlConstants.managerApi + "/wx/app")
public class WxAppController {

    private static final Logger log = LoggerFactory.getLogger(WxAppController.class);

    @Autowired
    private IThirdDeliveryService thirdDeliveryService;

    @GetMapping(value = "notify")
    public String wxNotify(@RequestParam String signature,@RequestParam String timestamp
            ,@RequestParam String nonce,@RequestParam String echostr) throws Exception{
        return echostr;
    }

    @PostMapping(value = "notify")
    public String wxNotify(@RequestBody @Valid WxNotifyDTO wxNotifyDTO) throws Exception{
        log.info("wxNotify:" + JSON.toJSONString(wxNotifyDTO));
        switch (EnumUtils.getEnumByType(wxNotifyDTO.getEvent(), WxEventType.class)){
            case add_express_path:
            {
                thirdDeliveryService.onDeliveryOrderChangeNotify(wxNotifyDTO);
                break;
            }
        }
        return null;
    }
}
