package com.red.circle.order.adapter.app;

import com.red.circle.order.app.dto.clientobject.PurchaseReceiptCO;
import com.red.circle.order.app.dto.cmd.ApplePurchaseCmd;
import com.red.circle.order.app.dto.cmd.GooglePurchaseCmd;
import com.red.circle.order.app.dto.cmd.HuaweiPurchaseCmd;
import com.red.circle.order.app.service.InAppPurchaseProductService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 内购.
 *
 * @author pengliang on 2023/8/16
 * @eo.api-type http
 * @eo.groupName 内购服务.应用内购
 * @eo.path /order/purchase-pay
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/purchase-pay", produces = MediaType.APPLICATION_JSON_VALUE)
public class PurchasePayRestController {

    private final InAppPurchaseProductService inAppPurchaseProductService;

    /**
     * Apple内购.
     *
     * @eo.name Apple 内购
     * @eo.url /apple
     * @eo.method post
     * @eo.request-type json
     */
    @PostMapping("/apple")
    public PurchaseReceiptCO apple(@RequestBody @Validated ApplePurchaseCmd cmd) {
        return inAppPurchaseProductService.purchase(cmd);
    }

    /**
     * Google内购.
     *
     * @eo.name Google内购
     * @eo.url /google
     * @eo.method post
     * @eo.request-type json
     */
    @PostMapping("/google")
    public PurchaseReceiptCO google(@RequestBody @Validated GooglePurchaseCmd cmd) {
        return inAppPurchaseProductService.purchase(cmd);
    }

    /**
     * 华为内购.
     *
     * @eo.name 华为内购
     * @eo.url /huawei
     * @eo.method post
     * @eo.request-type json
     */
    @PostMapping("/huawei")
    public PurchaseReceiptCO huawei(@RequestBody @Validated HuaweiPurchaseCmd cmd) {
        return inAppPurchaseProductService.purchase(cmd);
    }

}
