package com.tzld.piaoquan.api.controller.wecom;


import com.tzld.piaoquan.api.model.param.AccessTokenParam;
import com.tzld.piaoquan.api.model.param.CallbackParam;
import com.tzld.piaoquan.api.model.param.PushMessageParam;
import com.tzld.piaoquan.api.model.vo.*;
import com.tzld.piaoquan.api.mq.MessageCallbackProducer;
import com.tzld.piaoquan.api.service.GhAccessTokenService;
import com.tzld.piaoquan.api.service.wecom.ThirdPartyService;
import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/3rdParty")
public class ThirdPartyController {

    @Autowired
    private GhAccessTokenService ghAccessTokenService;

    @Autowired
    private ThirdPartyService thirdPartyService;

    @Autowired
    private MessageCallbackProducer messageCallbackProducer;

    @PostMapping("/accessToken/get")
    public CommonResponse<AccessTokenVo> getAccessToken(@RequestBody AccessTokenParam param) {
        return ghAccessTokenService.getAccessToken(param);
    }

    @PostMapping("/pushMessage/get")
    public CommonResponse<List<PushMessageVo>> getPushMessage(@RequestBody PushMessageParam param) {
        return thirdPartyService.getPushMessage(param);
    }

    @PostMapping("/pushMessage/callback")
    public CommonResponse<Void> pushMessageCallback(@RequestBody CallbackParam param) {
        return messageCallbackProducer.sendMessage(param);
    }

    @GetMapping("/report/uv")
    public CommonResponse<List<ReportUvVo>> getReportUv(@RequestParam String date, @RequestParam String accessToken) {
        return thirdPartyService.getReportUv(date, accessToken);
    }
}
