// File generated from our OpenAPI spec by Stainless.

package com.increase.api.models.wiretransfers

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

internal class WireTransferTest {

    @Test
    fun create() {
        val wireTransfer =
            WireTransfer.builder()
                .id("wire_transfer_5akynk7dqsq25qwk9q2u")
                .accountId("account_in71c4amph0vgo2qllky")
                .accountNumber("987654321")
                .amount(100L)
                .approval(
                    WireTransfer.Approval.builder()
                        .approvedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .approvedBy(null)
                        .build()
                )
                .cancellation(
                    WireTransfer.Cancellation.builder()
                        .canceledAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .canceledBy(null)
                        .build()
                )
                .createdAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                .createdBy(
                    WireTransfer.CreatedBy.builder()
                        .category(WireTransfer.CreatedBy.Category.USER)
                        .apiKey(
                            WireTransfer.CreatedBy.ApiKey.builder()
                                .description("description")
                                .build()
                        )
                        .oauthApplication(
                            WireTransfer.CreatedBy.OAuthApplication.builder().name("name").build()
                        )
                        .user(
                            WireTransfer.CreatedBy.User.builder().email("user@example.com").build()
                        )
                        .build()
                )
                .creditor(
                    WireTransfer.Creditor.builder()
                        .address(
                            WireTransfer.Creditor.Address.builder()
                                .unstructured(
                                    WireTransfer.Creditor.Address.Unstructured.builder()
                                        .line1("1500 Pennsylvania Avenue, NW")
                                        .line2("Washington, DC 20220")
                                        .line3(null)
                                        .build()
                                )
                                .build()
                        )
                        .name("National Phonograph Company")
                        .build()
                )
                .currency(WireTransfer.Currency.USD)
                .debtor(
                    WireTransfer.Debtor.builder()
                        .address(
                            WireTransfer.Debtor.Address.builder()
                                .unstructured(
                                    WireTransfer.Debtor.Address.Unstructured.builder()
                                        .line1("33 Liberty Street")
                                        .line2("New York, NY 10045")
                                        .line3(null)
                                        .build()
                                )
                                .build()
                        )
                        .name("Ian Crease")
                        .build()
                )
                .externalAccountId("external_account_ukk55lr923a3ac0pp7iv")
                .idempotencyKey(null)
                .inboundWireDrawdownRequestId(null)
                .network(WireTransfer.Network.WIRE)
                .pendingTransactionId(null)
                .remittance(
                    WireTransfer.Remittance.builder()
                        .category(WireTransfer.Remittance.Category.UNSTRUCTURED)
                        .tax(
                            WireTransfer.Remittance.Tax.builder()
                                .date(LocalDate.parse("2019-12-27"))
                                .identificationNumber("identification_number")
                                .typeCode("type_code")
                                .build()
                        )
                        .unstructured(
                            WireTransfer.Remittance.Unstructured.builder()
                                .message("Invoice 29582")
                                .build()
                        )
                        .build()
                )
                .reversal(
                    WireTransfer.Reversal.builder()
                        .amount(12345L)
                        .createdAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .debtorRoutingNumber("101050001")
                        .description("Inbound wire reversal 2022021100335128")
                        .inputCycleDate(LocalDate.parse("2022-02-11"))
                        .inputMessageAccountabilityData("20220211B6B7HU2R011023")
                        .inputSequenceNumber("11023")
                        .inputSource("B6B7HU2R")
                        .instructionIdentification(null)
                        .returnReasonAdditionalInformation(null)
                        .returnReasonCode(null)
                        .returnReasonCodeDescription(null)
                        .transactionId("transaction_uyrp7fld2ium70oa7oi")
                        .wireTransferId("wire_transfer_5akynk7dqsq25qwk9q2u")
                        .build()
                )
                .routingNumber("101050001")
                .sourceAccountNumberId("account_number_v18nkfqm6afpsrvy82b2")
                .status(WireTransfer.Status.COMPLETE)
                .submission(
                    WireTransfer.Submission.builder()
                        .inputMessageAccountabilityData("20220118MMQFMP0P000002")
                        .submittedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .build()
                )
                .transactionId("transaction_uyrp7fld2ium70oa7oi")
                .type(WireTransfer.Type.WIRE_TRANSFER)
                .uniqueEndToEndTransactionReference("9a21e10a-7600-4a24-8ff3-2cbc5943c27a")
                .build()

        assertThat(wireTransfer.id()).isEqualTo("wire_transfer_5akynk7dqsq25qwk9q2u")
        assertThat(wireTransfer.accountId()).isEqualTo("account_in71c4amph0vgo2qllky")
        assertThat(wireTransfer.accountNumber()).isEqualTo("987654321")
        assertThat(wireTransfer.amount()).isEqualTo(100L)
        assertThat(wireTransfer.approval())
            .contains(
                WireTransfer.Approval.builder()
                    .approvedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                    .approvedBy(null)
                    .build()
            )
        assertThat(wireTransfer.cancellation())
            .contains(
                WireTransfer.Cancellation.builder()
                    .canceledAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                    .canceledBy(null)
                    .build()
            )
        assertThat(wireTransfer.createdAt()).isEqualTo(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
        assertThat(wireTransfer.createdBy())
            .contains(
                WireTransfer.CreatedBy.builder()
                    .category(WireTransfer.CreatedBy.Category.USER)
                    .apiKey(
                        WireTransfer.CreatedBy.ApiKey.builder().description("description").build()
                    )
                    .oauthApplication(
                        WireTransfer.CreatedBy.OAuthApplication.builder().name("name").build()
                    )
                    .user(WireTransfer.CreatedBy.User.builder().email("user@example.com").build())
                    .build()
            )
        assertThat(wireTransfer.creditor())
            .contains(
                WireTransfer.Creditor.builder()
                    .address(
                        WireTransfer.Creditor.Address.builder()
                            .unstructured(
                                WireTransfer.Creditor.Address.Unstructured.builder()
                                    .line1("1500 Pennsylvania Avenue, NW")
                                    .line2("Washington, DC 20220")
                                    .line3(null)
                                    .build()
                            )
                            .build()
                    )
                    .name("National Phonograph Company")
                    .build()
            )
        assertThat(wireTransfer.currency()).isEqualTo(WireTransfer.Currency.USD)
        assertThat(wireTransfer.debtor())
            .contains(
                WireTransfer.Debtor.builder()
                    .address(
                        WireTransfer.Debtor.Address.builder()
                            .unstructured(
                                WireTransfer.Debtor.Address.Unstructured.builder()
                                    .line1("33 Liberty Street")
                                    .line2("New York, NY 10045")
                                    .line3(null)
                                    .build()
                            )
                            .build()
                    )
                    .name("Ian Crease")
                    .build()
            )
        assertThat(wireTransfer.externalAccountId())
            .contains("external_account_ukk55lr923a3ac0pp7iv")
        assertThat(wireTransfer.idempotencyKey()).isEmpty
        assertThat(wireTransfer.inboundWireDrawdownRequestId()).isEmpty
        assertThat(wireTransfer.network()).isEqualTo(WireTransfer.Network.WIRE)
        assertThat(wireTransfer.pendingTransactionId()).isEmpty
        assertThat(wireTransfer.remittance())
            .contains(
                WireTransfer.Remittance.builder()
                    .category(WireTransfer.Remittance.Category.UNSTRUCTURED)
                    .tax(
                        WireTransfer.Remittance.Tax.builder()
                            .date(LocalDate.parse("2019-12-27"))
                            .identificationNumber("identification_number")
                            .typeCode("type_code")
                            .build()
                    )
                    .unstructured(
                        WireTransfer.Remittance.Unstructured.builder()
                            .message("Invoice 29582")
                            .build()
                    )
                    .build()
            )
        assertThat(wireTransfer.reversal())
            .contains(
                WireTransfer.Reversal.builder()
                    .amount(12345L)
                    .createdAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                    .debtorRoutingNumber("101050001")
                    .description("Inbound wire reversal 2022021100335128")
                    .inputCycleDate(LocalDate.parse("2022-02-11"))
                    .inputMessageAccountabilityData("20220211B6B7HU2R011023")
                    .inputSequenceNumber("11023")
                    .inputSource("B6B7HU2R")
                    .instructionIdentification(null)
                    .returnReasonAdditionalInformation(null)
                    .returnReasonCode(null)
                    .returnReasonCodeDescription(null)
                    .transactionId("transaction_uyrp7fld2ium70oa7oi")
                    .wireTransferId("wire_transfer_5akynk7dqsq25qwk9q2u")
                    .build()
            )
        assertThat(wireTransfer.routingNumber()).isEqualTo("101050001")
        assertThat(wireTransfer.sourceAccountNumberId())
            .contains("account_number_v18nkfqm6afpsrvy82b2")
        assertThat(wireTransfer.status()).isEqualTo(WireTransfer.Status.COMPLETE)
        assertThat(wireTransfer.submission())
            .contains(
                WireTransfer.Submission.builder()
                    .inputMessageAccountabilityData("20220118MMQFMP0P000002")
                    .submittedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                    .build()
            )
        assertThat(wireTransfer.transactionId()).contains("transaction_uyrp7fld2ium70oa7oi")
        assertThat(wireTransfer.type()).isEqualTo(WireTransfer.Type.WIRE_TRANSFER)
        assertThat(wireTransfer.uniqueEndToEndTransactionReference())
            .contains("9a21e10a-7600-4a24-8ff3-2cbc5943c27a")
    }

    @Test
    fun roundtrip() {
        val jsonMapper = jsonMapper()
        val wireTransfer =
            WireTransfer.builder()
                .id("wire_transfer_5akynk7dqsq25qwk9q2u")
                .accountId("account_in71c4amph0vgo2qllky")
                .accountNumber("987654321")
                .amount(100L)
                .approval(
                    WireTransfer.Approval.builder()
                        .approvedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .approvedBy(null)
                        .build()
                )
                .cancellation(
                    WireTransfer.Cancellation.builder()
                        .canceledAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .canceledBy(null)
                        .build()
                )
                .createdAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                .createdBy(
                    WireTransfer.CreatedBy.builder()
                        .category(WireTransfer.CreatedBy.Category.USER)
                        .apiKey(
                            WireTransfer.CreatedBy.ApiKey.builder()
                                .description("description")
                                .build()
                        )
                        .oauthApplication(
                            WireTransfer.CreatedBy.OAuthApplication.builder().name("name").build()
                        )
                        .user(
                            WireTransfer.CreatedBy.User.builder().email("user@example.com").build()
                        )
                        .build()
                )
                .creditor(
                    WireTransfer.Creditor.builder()
                        .address(
                            WireTransfer.Creditor.Address.builder()
                                .unstructured(
                                    WireTransfer.Creditor.Address.Unstructured.builder()
                                        .line1("1500 Pennsylvania Avenue, NW")
                                        .line2("Washington, DC 20220")
                                        .line3(null)
                                        .build()
                                )
                                .build()
                        )
                        .name("National Phonograph Company")
                        .build()
                )
                .currency(WireTransfer.Currency.USD)
                .debtor(
                    WireTransfer.Debtor.builder()
                        .address(
                            WireTransfer.Debtor.Address.builder()
                                .unstructured(
                                    WireTransfer.Debtor.Address.Unstructured.builder()
                                        .line1("33 Liberty Street")
                                        .line2("New York, NY 10045")
                                        .line3(null)
                                        .build()
                                )
                                .build()
                        )
                        .name("Ian Crease")
                        .build()
                )
                .externalAccountId("external_account_ukk55lr923a3ac0pp7iv")
                .idempotencyKey(null)
                .inboundWireDrawdownRequestId(null)
                .network(WireTransfer.Network.WIRE)
                .pendingTransactionId(null)
                .remittance(
                    WireTransfer.Remittance.builder()
                        .category(WireTransfer.Remittance.Category.UNSTRUCTURED)
                        .tax(
                            WireTransfer.Remittance.Tax.builder()
                                .date(LocalDate.parse("2019-12-27"))
                                .identificationNumber("identification_number")
                                .typeCode("type_code")
                                .build()
                        )
                        .unstructured(
                            WireTransfer.Remittance.Unstructured.builder()
                                .message("Invoice 29582")
                                .build()
                        )
                        .build()
                )
                .reversal(
                    WireTransfer.Reversal.builder()
                        .amount(12345L)
                        .createdAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .debtorRoutingNumber("101050001")
                        .description("Inbound wire reversal 2022021100335128")
                        .inputCycleDate(LocalDate.parse("2022-02-11"))
                        .inputMessageAccountabilityData("20220211B6B7HU2R011023")
                        .inputSequenceNumber("11023")
                        .inputSource("B6B7HU2R")
                        .instructionIdentification(null)
                        .returnReasonAdditionalInformation(null)
                        .returnReasonCode(null)
                        .returnReasonCodeDescription(null)
                        .transactionId("transaction_uyrp7fld2ium70oa7oi")
                        .wireTransferId("wire_transfer_5akynk7dqsq25qwk9q2u")
                        .build()
                )
                .routingNumber("101050001")
                .sourceAccountNumberId("account_number_v18nkfqm6afpsrvy82b2")
                .status(WireTransfer.Status.COMPLETE)
                .submission(
                    WireTransfer.Submission.builder()
                        .inputMessageAccountabilityData("20220118MMQFMP0P000002")
                        .submittedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                        .build()
                )
                .transactionId("transaction_uyrp7fld2ium70oa7oi")
                .type(WireTransfer.Type.WIRE_TRANSFER)
                .uniqueEndToEndTransactionReference("9a21e10a-7600-4a24-8ff3-2cbc5943c27a")
                .build()

        val roundtrippedWireTransfer =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(wireTransfer),
                jacksonTypeRef<WireTransfer>(),
            )

        assertThat(roundtrippedWireTransfer).isEqualTo(wireTransfer)
    }
}
