package com.sonic.lion.controller.web;

import com.sonic.common.auth.domains.Session;
import com.sonic.common.rpc.Result;
import com.sonic.lion.domain.input.CreateSubscribeCheckSessionInput;
import com.sonic.lion.domain.input.UploadReceiptInput;
import com.sonic.lion.domain.output.CreateSubscribeCheckoutSessionOutput;
import com.sonic.lion.domain.req.UploadReceiptReq;
import com.sonic.lion.service.ReceiptHandlerService;
import com.sonic.lion.service.StripeSubscribeService;
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;

/**
 * 订阅相关
 * @author: code
 * @date: 2025/06/04
 * @Description:
 * @version: 1.0.0
 */
@Slf4j
@RestController
public class SubscribeController {

    @Autowired
    private ReceiptHandlerService receiptHandlerService;
    @Autowired
    private StripeSubscribeService stripeSubscribeService;

    @ApiOperation(value = "获取Stripe的订阅付款链接", tags = "订阅相关")
    @PostMapping("/web/pay/subscribe/stripe-checkout")
    public Result<CreateSubscribeCheckoutSessionOutput> stripeSubCheckout(@RequestBody @Validated CreateSubscribeCheckSessionInput input, @ApiParam(hidden = true) Session session) {
        return Result.success(stripeSubscribeService.createSubscribeCheckoutSession(session.getUserId(), input));
    }

    @ApiOperation(value = "上传IOS订阅收据", tags = "订阅相关")
    @PostMapping("/web/pay/subscribe/upload-apple-receipt")
    public Result<Void> uploadIosReceipt(@RequestBody @Validated UploadReceiptInput input, @ApiParam(hidden = true) Session session) {
        receiptHandlerService.uploadIosSubReceipt(session.getUserId(), input);
        return Result.success();
    }

    @ApiOperation(value = "上传Google订阅收据", tags = "订阅相关")
    @PostMapping("/web/pay/subscribe/upload-google-receipt")
    public Result uploadGoogleReceipt(@RequestBody @Validated UploadReceiptReq req, @ApiParam(hidden = true) Session session) {
        receiptHandlerService.uploadGoogleSubReceipt(session.getUserId(), req);
        return Result.success();
    }

}
