package com.tuoheng.admin.controller.callback;

import com.tuoheng.admin.request.third.DspCallbackRequest;
import com.tuoheng.admin.service.third.dsp.IDspCallbackService;
import com.tuoheng.common.core.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

/**
 * DSP回调-控制器
 *
 * @author 拓恒
 * @since 2021-09-01
 */
@RestController
@RequestMapping("/dsp/callback")
public class DspCallbackController {

    @Autowired
    private IDspCallbackService dspCallbackService;

    /**
     * 视频地址、问题图片回调接口
     *
     * @param dspCallbackRequest 回调请求体
     * @return JsonResult
     */
    @PostMapping("/{requestId}")
    public JsonResult callback(@Valid @Pattern(regexp = "^[a-zA-Z0-9]{0,36}$")
                               @NotBlank @PathVariable String requestId,
                               @Valid @RequestBody DspCallbackRequest dspCallbackRequest) {
        return dspCallbackService.saveCallbackData(requestId, dspCallbackRequest);
    }

}
