package com.tangem.features.swap.v2.impl.amount.ui.preview

import com.tangem.common.ui.account.AccountTitleUM
import com.tangem.common.ui.amountScreen.preview.AmountStatePreviewData
import com.tangem.core.ui.components.atoms.text.TextEllipsis
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.stringReference
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.express.models.ExpressProvider
import com.tangem.domain.express.models.ExpressProviderType
import com.tangem.domain.express.models.ExpressRateType
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.network.Network
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.domain.swap.models.SwapCurrencies
import com.tangem.domain.swap.models.SwapDirection
import com.tangem.domain.swap.models.SwapRateMode
import com.tangem.features.swap.v2.impl.amount.entity.SendSubtitleUM
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM
import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM
import kotlinx.collections.immutable.persistentListOf
import java.math.BigDecimal

internal data object SwapAmountContentPreview {

    val cryptoCurrencyStatus = CryptoCurrencyStatus(
        currency = CryptoCurrency.Coin(
            id = CryptoCurrency.ID.fromValue("coin⟨BITCOIN⟩bitcoin"),
            network = Network(
                id = Network.ID(
                    value = "bitcoin",
                    derivationPath = Network.DerivationPath.None,
                ),
                name = "Bitcoin",
                currencySymbol = "BTC",
                derivationPath = Network.DerivationPath.None,
                isTestnet = false,
                standardType = Network.StandardType.Unspecified("bitcoin"),
                hasFiatFeeRate = false,
                canHandleTokens = false,
                transactionExtrasType = Network.TransactionExtrasType.NONE,
                nameResolvingType = Network.NameResolvingType.NONE,
            ),
            name = "Bitcoin",
            symbol = "BTC",
            decimals = 8,
            iconUrl = "https://s3.eu-central-1.amazonaws.com/tangem.api/coins/medium/bitcoin.png",
            isCustom = false,
        ),
        value = CryptoCurrencyStatus.Loading,
    )

    private val provider = ExpressProvider(
        providerId = "changenow",
        rateTypes = listOf(ExpressRateType.Float),
        name = "ChangeNow",
        type = ExpressProviderType.CEX,
        imageLarge = "",
        termsOfUse = "",
        privacyPolicy = "",
        isRecommended = true,
        slippage = BigDecimal.ZERO,
    )

    private val quote = SwapQuoteUM.Content(
        provider = provider,
        toAmount = "123".toBigDecimal(),
        fromAmount = null,
        toAmountValue = stringReference("123"),
        fromAmountValue = TextReference.EMPTY,
        rate = stringReference("1 USD ≈ 123.123 POL"),
        diffPercent = SwapQuoteUM.Content.DifferencePercent.Best,
        isSingleProvider = false,
    )

    val emptyState = SwapAmountUM.Content(
        isPrimaryButtonEnabled = false,
        primaryAmount = SwapAmountFieldUM.Empty(
            amountType = SwapAmountType.From,
        ),
        secondaryAmount = SwapAmountFieldUM.Empty(
            amountType = SwapAmountType.To,
        ),
        swapDirection = SwapDirection.Direct,
        selectedAmountType = SwapAmountType.From,
        swapCurrencies = SwapCurrencies.EMPTY,
        swapQuotes = persistentListOf(),
        selectedQuote = SwapQuoteUM.Empty,
        primaryCryptoCurrencyStatus = cryptoCurrencyStatus,
        secondaryCryptoCurrencyStatus = cryptoCurrencyStatus,
        swapRateType = ExpressRateType.Float,
        appCurrency = AppCurrency.Default,
        isShowBestRateAnimation = false,
        isShowFCAWarning = false,
        priceImpact = null,
        swapRateMode = SwapRateMode.FLOAT_ONLY,
    )

    val defaultState = SwapAmountUM.Content(
        primaryAmount = SwapAmountFieldUM.Content(
            amountType = SwapAmountType.From,
            amountField = AmountStatePreviewData.amountState,
            title = stringReference("Tether"),
            subtitleLeft = stringReference("Balance: 11 101,123123456 BTC"),
            subtitleRight = TextReference.EMPTY,
            isClickEnabled = false,
            subtitleEllipsisLeft = TextEllipsis.OffsetEnd(3),
            subtitleEllipsisRight = TextEllipsis.OffsetEnd(1),
            shouldShowApproximatePrefix = false,
            sendSubtitle = SendSubtitleUM(
                label = stringReference("Send:"),
                value = stringReference("1 212,12 BTC"),
                valueEllipsis = TextEllipsis.OffsetEnd(3),
            ),
        ),
        secondaryAmount = SwapAmountFieldUM.Content(
            amountType = SwapAmountType.To,
            amountField = AmountStatePreviewData.amountState.copy(
                accountTitleUM = AccountTitleUM.Text(stringReference("Amount to receive")),
            ),
            title = stringReference("Shiba Inu"),
            subtitleLeft = TextReference.EMPTY,
            subtitleRight = TextReference.EMPTY,
            isClickEnabled = false,
            subtitleEllipsisLeft = TextEllipsis.End,
            subtitleEllipsisRight = TextEllipsis.End,
            shouldShowApproximatePrefix = true,
        ),
        appCurrency = AppCurrency.Default,
        swapDirection = SwapDirection.Direct,
        selectedAmountType = SwapAmountType.From,
        swapCurrencies = SwapCurrencies.EMPTY,
        swapQuotes = persistentListOf(),
        selectedQuote = quote,
        primaryCryptoCurrencyStatus = cryptoCurrencyStatus,
        secondaryCryptoCurrencyStatus = cryptoCurrencyStatus,
        swapRateType = ExpressRateType.Fixed,
        isPrimaryButtonEnabled = true,
        isShowBestRateAnimation = false,
        isShowFCAWarning = true,
        priceImpact = null,
        swapRateMode = SwapRateMode.FLOAT_AND_FIXED,
    )

    val defaultStateAccount: SwapAmountUM.Content
        get() = defaultState.copy(
            primaryAmount = (defaultState.primaryAmount as SwapAmountFieldUM.Content).copy(
                amountField = AmountStatePreviewData.amountStateV2Accounts,
            ),
            secondaryAmount = (defaultState.secondaryAmount as SwapAmountFieldUM.Content).copy(
                amountField = AmountStatePreviewData.amountStateV2Accounts.copy(
                    accountTitleUM = AccountTitleUM.Text(stringReference("Amount to receive")),
                ),
            ),
        )
}