package com.red.circle.order.app.command.pay.app.strategy.extract;

import com.red.circle.order.app.command.pay.app.model.ExtractInAppPurchaseReceipt;
import com.red.circle.order.app.command.pay.app.receipt.AssemblyOrder;
import com.red.circle.order.app.dto.cmd.AbstractPurchaseCmd;
import com.red.circle.order.app.dto.cmd.TelegramPurchaseCmd;
import com.red.circle.order.infra.database.rds.entity.order.OrderTelegramPurchase;
import com.red.circle.order.infra.database.rds.service.order.OrderTelegramPurchaseService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * Description:
 *
 * @author 金泽强
 * @date 2024/12/10 16:38
 */
@Slf4j
@Component("telegramExtractAppPurchaseOrderStrategy")
@RequiredArgsConstructor
public class TelegramExtractAppPurchaseOrderStrategy implements ExtractAppPurchaseOrderStrategy {

    private final OrderTelegramPurchaseService orderTelegramPurchaseService;

    @Override
    public ExtractInAppPurchaseReceipt doOperation(AbstractPurchaseCmd cmd) {
        TelegramPurchaseCmd playParam = (TelegramPurchaseCmd) cmd;
        String invoicePayload = playParam.getInvoicePayload();
        OrderTelegramPurchase orderTelegramPurchase = orderTelegramPurchaseService.getById(invoicePayload);
        return AssemblyOrder.toTelegramExtractInAppPurchaseReceipt(playParam, orderTelegramPurchase);
    }
}
