package com.r35157.libs.jupiter.swap;

import com.r35157.libs.valuetypes.basic.MoneyAmount;
import org.jetbrains.annotations.NotNull;

import java.math.BigDecimal;
import java.util.Objects;

/**
 * Result of a successfully executed Jupiter token swap.
 *
 * @param transactionSignature confirmed Solana transaction signature
 * @param spentInputTokenAmount actual input-token amount deducted from the
 *                              wallet, in human-readable units
 * @param receivedOutputTokenAmount actual output-token amount received by the
 *                                  wallet, in human-readable units
 */
public record JupiterSwapResult(
        @NotNull ΩSolanaTransactionSignatureΩ transactionSignature,
        @NotNull ΩAmountΩ spentInputTokenAmount,
        @NotNull ΩAmountΩ receivedOutputTokenAmount
) {
    /**
     * Validates the successful swap result.
     */
    public JupiterSwapResult {
        Objects.requireNonNull(
                transactionSignature,
                "transactionSignature"
        );
        Objects.requireNonNull(
                spentInputTokenAmount,
                "spentInputTokenAmount"
        );
        Objects.requireNonNull(
                receivedOutputTokenAmount,
                "receivedOutputTokenAmount"
        );

        if (transactionSignature.isBlank()) {
            throw new IllegalArgumentException(
                    "Transaction signature must not be blank"
            );
        }
        if (spentInputTokenAmount.signum() <= 0) {
            throw new IllegalArgumentException(
                    "Spent input-token amount must be greater than zero"
            );
        }
        if (receivedOutputTokenAmount.signum() <= 0) {
            throw new IllegalArgumentException(
                    "Received output-token amount must be greater than zero"
            );
        }
    }
}
