package cn.axzo.msg.center.notices.service.impl;

import cn.axzo.msg.center.api.MnsCallbackApi;
import cn.axzo.msg.center.api.request.AliMessageCallbackRequestDto;
import cn.axzo.msg.center.api.response.AliCallbackResponseDto;
import cn.axzo.msg.center.notices.service.api.MessageCallbackService;
import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yanglin
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class MnsCallbackApiImpl implements MnsCallbackApi {

    private final MessageCallbackService messageCallbackService;

    @Override
    public AliCallbackResponseDto aliCallback(List<AliMessageCallbackRequestDto> request) {
        AliCallbackResponseDto response = null;
        try {
            response = messageCallbackService.aliCallbackHandle(request);
        } finally {
            log.info("ali mns callback, request: {}, response={}",
                    JSON.toJSONString(request), JSON.toJSONString(response));
        }
        return response;
    }

}