package com.yida.data.system.controller;


import com.yida.data.system.service.WxPublicService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "微信公众号同步")
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/in/wxPublic")
public class InWxPublicController {

    private final WxPublicService wxPublicService;

    @GetMapping("/callback/{appId}")
    public String get(@RequestParam("signature") String signature,
        @RequestParam("timestamp") String timestamp,
        @RequestParam("nonce") String nonce,
        @RequestParam("echostr") String echostr,
        @PathVariable("appId") String appId) {
        return wxPublicService.get(signature, timestamp, nonce, echostr, appId);
    }

    @PostMapping("/callback/{appId}")
    public String post(
        @RequestParam("msg_signature") String msgSignature,
        @RequestParam("timestamp") String timestamp,
        @RequestParam("nonce") String nonce,
        @RequestBody String body,
        @PathVariable("appId") String appId) {
        wxPublicService.post(msgSignature, timestamp, nonce, body, appId);
        return "";
    }
}
