// File generated from our OpenAPI spec by Stainless.

package com.increase.api.models.checkdeposits

import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
import com.increase.api.core.jsonMapper
import java.time.OffsetDateTime
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

internal class CheckDepositTest {

    @Test
    fun create() {
        val checkDeposit =
            CheckDeposit.builder()
                .id("check_deposit_f06n9gpg7sxn8t19lfc1")
                .accountId("account_in71c4amph0vgo2qllky")
                .amount(1000L)
                .backImageFileId("file_26khfk98mzfz90a11oqx")
                .createdAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                .depositAcceptance(
                    CheckDeposit.DepositAcceptance.builder()
                        .accountNumber("987654321")
                        .amount(1000L)
                        .auxiliaryOnUs("101")
                        .checkDepositId("check_deposit_f06n9gpg7sxn8t19lfc1")
                        .currency(CheckDeposit.DepositAcceptance.Currency.USD)
                        .routingNumber("101050001")
                        .serialNumber(null)
                        .build()
                )
                .addDepositAdjustment(
                    CheckDeposit.DepositAdjustment.builder()
                        .adjustedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .amount(1750L)
                        .reason(CheckDeposit.DepositAdjustment.Reason.ADJUSTED_AMOUNT)
                        .transactionId("transaction_uyrp7fld2ium70oa7oi")
                        .build()
                )
                .depositRejection(
                    CheckDeposit.DepositRejection.builder()
                        .amount(1750L)
                        .checkDepositId("check_deposit_f06n9gpg7sxn8t19lfc1")
                        .currency(CheckDeposit.DepositRejection.Currency.USD)
                        .declinedTransactionId("declined_transaction_17jbn0yyhvkt4v4ooym8")
                        .reason(CheckDeposit.DepositRejection.Reason.INCOMPLETE_IMAGE)
                        .rejectedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .build()
                )
                .depositReturn(
                    CheckDeposit.DepositReturn.builder()
                        .amount(100L)
                        .checkDepositId("check_deposit_f06n9gpg7sxn8t19lfc1")
                        .currency(CheckDeposit.DepositReturn.Currency.USD)
                        .returnReason(CheckDeposit.DepositReturn.ReturnReason.INSUFFICIENT_FUNDS)
                        .returnedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .transactionId("transaction_uyrp7fld2ium70oa7oi")
                        .build()
                )
                .depositSubmission(
                    CheckDeposit.DepositSubmission.builder()
                        .backFileId("file_frhw4s443nh7noss55kq")
                        .frontFileId("file_j7ed9mrve741m6yui9ju")
                        .submittedAt(OffsetDateTime.parse("2020-02-01T00:59:59+00:00"))
                        .build()
                )
                .description(null)
                .frontImageFileId("file_makxrc67oh9l6sg7w9yc")
                .idempotencyKey(null)
                .inboundFundsHold(
                    CheckDeposit.InboundFundsHold.builder()
                        .amount(100L)
                        .automaticallyReleasesAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .createdAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .currency(CheckDeposit.InboundFundsHold.Currency.USD)
                        .heldTransactionId("transaction_uyrp7fld2ium70oa7oi")
                        .pendingTransactionId("pending_transaction_k1sfetcau2qbvjbzgju4")
                        .releasedAt(null)
                        .status(CheckDeposit.InboundFundsHold.Status.HELD)
                        .type(CheckDeposit.InboundFundsHold.Type.INBOUND_FUNDS_HOLD)
                        .build()
                )
                .inboundMailItemId(null)
                .lockboxRecipientId(null)
                .status(CheckDeposit.Status.SUBMITTED)
                .transactionId("transaction_uyrp7fld2ium70oa7oi")
                .type(CheckDeposit.Type.CHECK_DEPOSIT)
                .build()

        assertThat(checkDeposit.id()).isEqualTo("check_deposit_f06n9gpg7sxn8t19lfc1")
        assertThat(checkDeposit.accountId()).isEqualTo("account_in71c4amph0vgo2qllky")
        assertThat(checkDeposit.amount()).isEqualTo(1000L)
        assertThat(checkDeposit.backImageFileId()).contains("file_26khfk98mzfz90a11oqx")
        assertThat(checkDeposit.createdAt()).isEqualTo(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
        assertThat(checkDeposit.depositAcceptance())
            .contains(
                CheckDeposit.DepositAcceptance.builder()
                    .accountNumber("987654321")
                    .amount(1000L)
                    .auxiliaryOnUs("101")
                    .checkDepositId("check_deposit_f06n9gpg7sxn8t19lfc1")
                    .currency(CheckDeposit.DepositAcceptance.Currency.USD)
                    .routingNumber("101050001")
                    .serialNumber(null)
                    .build()
            )
        assertThat(checkDeposit.depositAdjustments())
            .containsExactly(
                CheckDeposit.DepositAdjustment.builder()
                    .adjustedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                    .amount(1750L)
                    .reason(CheckDeposit.DepositAdjustment.Reason.ADJUSTED_AMOUNT)
                    .transactionId("transaction_uyrp7fld2ium70oa7oi")
                    .build()
            )
        assertThat(checkDeposit.depositRejection())
            .contains(
                CheckDeposit.DepositRejection.builder()
                    .amount(1750L)
                    .checkDepositId("check_deposit_f06n9gpg7sxn8t19lfc1")
                    .currency(CheckDeposit.DepositRejection.Currency.USD)
                    .declinedTransactionId("declined_transaction_17jbn0yyhvkt4v4ooym8")
                    .reason(CheckDeposit.DepositRejection.Reason.INCOMPLETE_IMAGE)
                    .rejectedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                    .build()
            )
        assertThat(checkDeposit.depositReturn())
            .contains(
                CheckDeposit.DepositReturn.builder()
                    .amount(100L)
                    .checkDepositId("check_deposit_f06n9gpg7sxn8t19lfc1")
                    .currency(CheckDeposit.DepositReturn.Currency.USD)
                    .returnReason(CheckDeposit.DepositReturn.ReturnReason.INSUFFICIENT_FUNDS)
                    .returnedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                    .transactionId("transaction_uyrp7fld2ium70oa7oi")
                    .build()
            )
        assertThat(checkDeposit.depositSubmission())
            .contains(
                CheckDeposit.DepositSubmission.builder()
                    .backFileId("file_frhw4s443nh7noss55kq")
                    .frontFileId("file_j7ed9mrve741m6yui9ju")
                    .submittedAt(OffsetDateTime.parse("2020-02-01T00:59:59+00:00"))
                    .build()
            )
        assertThat(checkDeposit.description()).isEmpty
        assertThat(checkDeposit.frontImageFileId()).isEqualTo("file_makxrc67oh9l6sg7w9yc")
        assertThat(checkDeposit.idempotencyKey()).isEmpty
        assertThat(checkDeposit.inboundFundsHold())
            .contains(
                CheckDeposit.InboundFundsHold.builder()
                    .amount(100L)
                    .automaticallyReleasesAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                    .createdAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                    .currency(CheckDeposit.InboundFundsHold.Currency.USD)
                    .heldTransactionId("transaction_uyrp7fld2ium70oa7oi")
                    .pendingTransactionId("pending_transaction_k1sfetcau2qbvjbzgju4")
                    .releasedAt(null)
                    .status(CheckDeposit.InboundFundsHold.Status.HELD)
                    .type(CheckDeposit.InboundFundsHold.Type.INBOUND_FUNDS_HOLD)
                    .build()
            )
        assertThat(checkDeposit.inboundMailItemId()).isEmpty
        assertThat(checkDeposit.lockboxRecipientId()).isEmpty
        assertThat(checkDeposit.status()).isEqualTo(CheckDeposit.Status.SUBMITTED)
        assertThat(checkDeposit.transactionId()).contains("transaction_uyrp7fld2ium70oa7oi")
        assertThat(checkDeposit.type()).isEqualTo(CheckDeposit.Type.CHECK_DEPOSIT)
    }

    @Test
    fun roundtrip() {
        val jsonMapper = jsonMapper()
        val checkDeposit =
            CheckDeposit.builder()
                .id("check_deposit_f06n9gpg7sxn8t19lfc1")
                .accountId("account_in71c4amph0vgo2qllky")
                .amount(1000L)
                .backImageFileId("file_26khfk98mzfz90a11oqx")
                .createdAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                .depositAcceptance(
                    CheckDeposit.DepositAcceptance.builder()
                        .accountNumber("987654321")
                        .amount(1000L)
                        .auxiliaryOnUs("101")
                        .checkDepositId("check_deposit_f06n9gpg7sxn8t19lfc1")
                        .currency(CheckDeposit.DepositAcceptance.Currency.USD)
                        .routingNumber("101050001")
                        .serialNumber(null)
                        .build()
                )
                .addDepositAdjustment(
                    CheckDeposit.DepositAdjustment.builder()
                        .adjustedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .amount(1750L)
                        .reason(CheckDeposit.DepositAdjustment.Reason.ADJUSTED_AMOUNT)
                        .transactionId("transaction_uyrp7fld2ium70oa7oi")
                        .build()
                )
                .depositRejection(
                    CheckDeposit.DepositRejection.builder()
                        .amount(1750L)
                        .checkDepositId("check_deposit_f06n9gpg7sxn8t19lfc1")
                        .currency(CheckDeposit.DepositRejection.Currency.USD)
                        .declinedTransactionId("declined_transaction_17jbn0yyhvkt4v4ooym8")
                        .reason(CheckDeposit.DepositRejection.Reason.INCOMPLETE_IMAGE)
                        .rejectedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .build()
                )
                .depositReturn(
                    CheckDeposit.DepositReturn.builder()
                        .amount(100L)
                        .checkDepositId("check_deposit_f06n9gpg7sxn8t19lfc1")
                        .currency(CheckDeposit.DepositReturn.Currency.USD)
                        .returnReason(CheckDeposit.DepositReturn.ReturnReason.INSUFFICIENT_FUNDS)
                        .returnedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .transactionId("transaction_uyrp7fld2ium70oa7oi")
                        .build()
                )
                .depositSubmission(
                    CheckDeposit.DepositSubmission.builder()
                        .backFileId("file_frhw4s443nh7noss55kq")
                        .frontFileId("file_j7ed9mrve741m6yui9ju")
                        .submittedAt(OffsetDateTime.parse("2020-02-01T00:59:59+00:00"))
                        .build()
                )
                .description(null)
                .frontImageFileId("file_makxrc67oh9l6sg7w9yc")
                .idempotencyKey(null)
                .inboundFundsHold(
                    CheckDeposit.InboundFundsHold.builder()
                        .amount(100L)
                        .automaticallyReleasesAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .createdAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .currency(CheckDeposit.InboundFundsHold.Currency.USD)
                        .heldTransactionId("transaction_uyrp7fld2ium70oa7oi")
                        .pendingTransactionId("pending_transaction_k1sfetcau2qbvjbzgju4")
                        .releasedAt(null)
                        .status(CheckDeposit.InboundFundsHold.Status.HELD)
                        .type(CheckDeposit.InboundFundsHold.Type.INBOUND_FUNDS_HOLD)
                        .build()
                )
                .inboundMailItemId(null)
                .lockboxRecipientId(null)
                .status(CheckDeposit.Status.SUBMITTED)
                .transactionId("transaction_uyrp7fld2ium70oa7oi")
                .type(CheckDeposit.Type.CHECK_DEPOSIT)
                .build()

        val roundtrippedCheckDeposit =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(checkDeposit),
                jacksonTypeRef<CheckDeposit>(),
            )

        assertThat(roundtrippedCheckDeposit).isEqualTo(checkDeposit)
    }
}
