package com.sqx.modules.callback;
import com.sqx.common.exception.CzgException;
import com.sqx.modules.callback.service.UniAdCallbackRecordService;
import lombok.extern.slf4j.Slf4j;

import com.sqx.modules.callback.dao.UniAdCallBackDTO;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/uniCallBack")
@Slf4j
public class UniCallBackController {
    private final UniAdCallbackRecordService uniCallBackService;

    public UniCallBackController(UniAdCallbackRecordService uniCallBackService) {
        this.uniCallBackService = uniCallBackService;
    }

    @GetMapping("/adCallBack")
    public ResponseEntity<?> adCallBack(@RequestParam String adpid, @RequestParam String provider,
                                        @RequestParam String platform, @RequestParam String sign, @RequestParam String trans_id,
                                        @RequestParam String user_id, @RequestParam(required = false) String extra) {
        UniAdCallBackDTO dto = new UniAdCallBackDTO();
        dto.setAdpid(adpid);
        dto.setProvider(provider);
        dto.setPlatform(platform);
        dto.setSign(sign);
        dto.setTrans_id(trans_id);
        dto.setUser_id(user_id);
        dto.setExtra(extra);
        log.info("接收到uni-ad广告完播回调，回调信息: {}", dto);
        return ResponseEntity.ok(uniCallBackService.adCallBack(dto));
    }

    @GetMapping("/testException")
    public String testException() throws CzgException {
        throw new CzgException("测试异常");
    }
}
