package com.yida.data.system.controller;

import com.yida.data.common.core.common.ResultBean;
import com.yida.data.system.service.QywxCallbackService;

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;

import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;

@Api(tags = "企业微信同步")
@RestController
@RequiredArgsConstructor
@RequestMapping("/in/qywx")
public class InQywxController {

    private final QywxCallbackService qywxCallbackService;

    @GetMapping("/callback/{corpId}")
    public String get(@PathVariable String corpId,
                      @RequestParam("msg_signature") String msgSignature,
                      @RequestParam("timestamp") String timestamp,
                      @RequestParam("nonce") String nonce,
                      @RequestParam("echostr") String echostr
    ) {
        return qywxCallbackService.get(corpId, msgSignature, timestamp, nonce, echostr);
    }

    @PostMapping("/callback/{corpId}")
    public Object post(@PathVariable String corpId,
                       @RequestParam("msg_signature") String msgSignature,
                       @RequestParam("timestamp") String timestamp,
                       @RequestParam("nonce") String nonce,
                       @RequestBody String body) {
        qywxCallbackService.post(corpId, msgSignature, timestamp, nonce, body);
        return ResultBean.buildSuccess();
    }

}
