package com.sonic.lion.controller.web;

import com.sonic.common.auth.domains.Session;
import com.sonic.common.rpc.Result;
import com.sonic.lion.domain.req.IapUploadReceiptReq;
import com.sonic.lion.service.IapService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
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 static com.sonic.common.rpc.Result.success;

/**
 * Apple回调
 * @author: code
 */
@Slf4j
@RestController
public class WebhookAppleController {

    @Autowired
    private IapService iapService;

    @ApiOperation(value = "iOS前端上传收据", tags = "Apple回调")
    @PostMapping("/web/pay/webhooks/iap")
    public Result<Void> iap(@RequestBody @Validated IapUploadReceiptReq req, @ApiParam(hidden = true) Session session) {
        iapService.uploadReceipt(req, session.getUserId());
        return success();
    }

}
