package com.backendsys.modules.sdk.tencentcloud.ems.controller;

import com.backendsys.modules.common.config.security.annotations.Anonymous;
import com.backendsys.modules.common.utils.Result;
import com.backendsys.modules.sdk.tencentcloud.ems.entity.TencentEmsCallbackParams;
import com.backendsys.modules.sdk.tencentcloud.ems.service.TencentEmsService;
import com.backendsys.modules.sdk.tencentcloud.ems.service.TencentEmsCallbackService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@RestController
@Tag(name = "腾讯云-邮件回调")
public class TencentEmsController {

//    @Autowired
//    private TencentEmsService tencentEmsService;

    @Autowired
    private TencentEmsCallbackService tencentEmsCallbackService;

    //@Anonymous
    //@Operation(summary = "邮件推送 (测试)")
    //@GetMapping("/api/ems/send")
    //public Result send(String email) {
    //    String templateParamSet = "{ \"code\": \"123456\", \"minute\": \"5\" }";
    //    return Result.success().put("data", tencentEmsService.send("邮件测试", 140698L, templateParamSet, email));
    //}

    /**
     * [回调] 邮件通知事件
     * https://cloud.tencent.com/document/product/1288/52368
     */
    @Anonymous
    @Operation(summary = "邮件推送通知事件回调")
    @PostMapping("/api/ems/callback")
    public Result receiveCallback(@Validated(TencentEmsCallbackParams.Callback.class) @RequestBody TencentEmsCallbackParams tencentEmsCallbackParams) {
        //System.out.println("===============================");
        //System.out.println("邮件推送通知事件回调");
        //System.out.println("body 参数: " + tencentEmsCallbackParams);
        //System.out.println("===============================");
        tencentEmsCallbackService.receiveCallback(tencentEmsCallbackParams);
        return Result.success();
    }

}
