// File generated from our OpenAPI spec by Stainless.

package com.increase.api.services.blocking

import com.increase.api.TestServerExtension
import com.increase.api.client.okhttp.IncreaseOkHttpClient
import com.increase.api.models.entities.EntityCreateParams
import com.increase.api.models.entities.EntityUpdateParams
import java.time.LocalDate
import java.time.OffsetDateTime
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith

@ExtendWith(TestServerExtension::class)
internal class EntityServiceTest {

    @Test
    fun create() {
        val client =
            IncreaseOkHttpClient.builder()
                .baseUrl(TestServerExtension.BASE_URL)
                .apiKey("My API Key")
                .build()
        val entityService = client.entities()

        val entity =
            entityService.create(
                EntityCreateParams.builder()
                    .structure(EntityCreateParams.Structure.CORPORATION)
                    .corporation(
                        EntityCreateParams.Corporation.builder()
                            .address(
                                EntityCreateParams.Corporation.Address.builder()
                                    .city("New York")
                                    .country("x")
                                    .line1("33 Liberty Street")
                                    .line2("x")
                                    .state("NY")
                                    .zip("10045")
                                    .build()
                            )
                            .addBeneficialOwner(
                                EntityCreateParams.Corporation.BeneficialOwner.builder()
                                    .individual(
                                        EntityCreateParams.Corporation.BeneficialOwner.Individual
                                            .builder()
                                            .address(
                                                EntityCreateParams.Corporation.BeneficialOwner
                                                    .Individual
                                                    .Address
                                                    .builder()
                                                    .city("New York")
                                                    .country("x")
                                                    .line1("33 Liberty Street")
                                                    .line2("x")
                                                    .state("NY")
                                                    .zip("10045")
                                                    .build()
                                            )
                                            .dateOfBirth(LocalDate.parse("1970-01-31"))
                                            .identification(
                                                EntityCreateParams.Corporation.BeneficialOwner
                                                    .Individual
                                                    .Identification
                                                    .builder()
                                                    .method(
                                                        EntityCreateParams.Corporation
                                                            .BeneficialOwner
                                                            .Individual
                                                            .Identification
                                                            .Method
                                                            .SOCIAL_SECURITY_NUMBER
                                                    )
                                                    .number("078051120")
                                                    .driversLicense(
                                                        EntityCreateParams.Corporation
                                                            .BeneficialOwner
                                                            .Individual
                                                            .Identification
                                                            .DriversLicense
                                                            .builder()
                                                            .expirationDate(
                                                                LocalDate.parse("2019-12-27")
                                                            )
                                                            .fileId("file_id")
                                                            .state("xx")
                                                            .backFileId("back_file_id")
                                                            .build()
                                                    )
                                                    .other(
                                                        EntityCreateParams.Corporation
                                                            .BeneficialOwner
                                                            .Individual
                                                            .Identification
                                                            .Other
                                                            .builder()
                                                            .country("x")
                                                            .description("x")
                                                            .fileId("file_id")
                                                            .backFileId("back_file_id")
                                                            .expirationDate(
                                                                LocalDate.parse("2019-12-27")
                                                            )
                                                            .build()
                                                    )
                                                    .passport(
                                                        EntityCreateParams.Corporation
                                                            .BeneficialOwner
                                                            .Individual
                                                            .Identification
                                                            .Passport
                                                            .builder()
                                                            .country("x")
                                                            .expirationDate(
                                                                LocalDate.parse("2019-12-27")
                                                            )
                                                            .fileId("file_id")
                                                            .build()
                                                    )
                                                    .build()
                                            )
                                            .name("Ian Crease")
                                            .confirmedNoUsTaxId(true)
                                            .build()
                                    )
                                    .addProng(
                                        EntityCreateParams.Corporation.BeneficialOwner.Prong.CONTROL
                                    )
                                    .companyTitle("CEO")
                                    .build()
                            )
                            .legalIdentifier(
                                EntityCreateParams.Corporation.LegalIdentifier.builder()
                                    .value("602214076")
                                    .category(
                                        EntityCreateParams.Corporation.LegalIdentifier.Category
                                            .US_EMPLOYER_IDENTIFICATION_NUMBER
                                    )
                                    .build()
                            )
                            .name("National Phonograph Company")
                            .beneficialOwnershipExemptionReason(
                                EntityCreateParams.Corporation.BeneficialOwnershipExemptionReason
                                    .REGULATED_FINANCIAL_INSTITUTION
                            )
                            .email("dev@stainless.com")
                            .incorporationState("NY")
                            .industryCode("x")
                            .website("https://example.com")
                            .build()
                    )
                    .description("x")
                    .governmentAuthority(
                        EntityCreateParams.GovernmentAuthority.builder()
                            .address(
                                EntityCreateParams.GovernmentAuthority.Address.builder()
                                    .city("x")
                                    .line1("x")
                                    .state("xx")
                                    .zip("x")
                                    .line2("x")
                                    .build()
                            )
                            .addAuthorizedPerson(
                                EntityCreateParams.GovernmentAuthority.AuthorizedPerson.builder()
                                    .name("x")
                                    .build()
                            )
                            .category(EntityCreateParams.GovernmentAuthority.Category.MUNICIPALITY)
                            .name("x")
                            .taxIdentifier("x")
                            .website("website")
                            .build()
                    )
                    .joint(
                        EntityCreateParams.Joint.builder()
                            .addIndividual(
                                EntityCreateParams.Joint.Individual.builder()
                                    .address(
                                        EntityCreateParams.Joint.Individual.Address.builder()
                                            .city("x")
                                            .country("x")
                                            .line1("x")
                                            .line2("x")
                                            .state("x")
                                            .zip("x")
                                            .build()
                                    )
                                    .dateOfBirth(LocalDate.parse("2019-12-27"))
                                    .identification(
                                        EntityCreateParams.Joint.Individual.Identification.builder()
                                            .method(
                                                EntityCreateParams.Joint.Individual.Identification
                                                    .Method
                                                    .SOCIAL_SECURITY_NUMBER
                                            )
                                            .number("xxxx")
                                            .driversLicense(
                                                EntityCreateParams.Joint.Individual.Identification
                                                    .DriversLicense
                                                    .builder()
                                                    .expirationDate(LocalDate.parse("2019-12-27"))
                                                    .fileId("file_id")
                                                    .state("xx")
                                                    .backFileId("back_file_id")
                                                    .build()
                                            )
                                            .other(
                                                EntityCreateParams.Joint.Individual.Identification
                                                    .Other
                                                    .builder()
                                                    .country("x")
                                                    .description("x")
                                                    .fileId("file_id")
                                                    .backFileId("back_file_id")
                                                    .expirationDate(LocalDate.parse("2019-12-27"))
                                                    .build()
                                            )
                                            .passport(
                                                EntityCreateParams.Joint.Individual.Identification
                                                    .Passport
                                                    .builder()
                                                    .country("x")
                                                    .expirationDate(LocalDate.parse("2019-12-27"))
                                                    .fileId("file_id")
                                                    .build()
                                            )
                                            .build()
                                    )
                                    .name("x")
                                    .confirmedNoUsTaxId(true)
                                    .build()
                            )
                            .build()
                    )
                    .naturalPerson(
                        EntityCreateParams.NaturalPerson.builder()
                            .address(
                                EntityCreateParams.NaturalPerson.Address.builder()
                                    .city("x")
                                    .country("x")
                                    .line1("x")
                                    .line2("x")
                                    .state("x")
                                    .zip("x")
                                    .build()
                            )
                            .dateOfBirth(LocalDate.parse("2019-12-27"))
                            .identification(
                                EntityCreateParams.NaturalPerson.Identification.builder()
                                    .method(
                                        EntityCreateParams.NaturalPerson.Identification.Method
                                            .SOCIAL_SECURITY_NUMBER
                                    )
                                    .number("xxxx")
                                    .driversLicense(
                                        EntityCreateParams.NaturalPerson.Identification
                                            .DriversLicense
                                            .builder()
                                            .expirationDate(LocalDate.parse("2019-12-27"))
                                            .fileId("file_id")
                                            .state("xx")
                                            .backFileId("back_file_id")
                                            .build()
                                    )
                                    .other(
                                        EntityCreateParams.NaturalPerson.Identification.Other
                                            .builder()
                                            .country("x")
                                            .description("x")
                                            .fileId("file_id")
                                            .backFileId("back_file_id")
                                            .expirationDate(LocalDate.parse("2019-12-27"))
                                            .build()
                                    )
                                    .passport(
                                        EntityCreateParams.NaturalPerson.Identification.Passport
                                            .builder()
                                            .country("x")
                                            .expirationDate(LocalDate.parse("2019-12-27"))
                                            .fileId("file_id")
                                            .build()
                                    )
                                    .build()
                            )
                            .name("x")
                            .confirmedNoUsTaxId(true)
                            .build()
                    )
                    .riskRating(
                        EntityCreateParams.RiskRating.builder()
                            .ratedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
                            .rating(EntityCreateParams.RiskRating.Rating.LOW)
                            .build()
                    )
                    .addSupplementalDocument(
                        EntityCreateParams.SupplementalDocument.builder().fileId("file_id").build()
                    )
                    .addTermsAgreement(
                        EntityCreateParams.TermsAgreement.builder()
                            .agreedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
                            .ipAddress("x")
                            .termsUrl("x")
                            .build()
                    )
                    .thirdPartyVerification(
                        EntityCreateParams.ThirdPartyVerification.builder()
                            .reference("x")
                            .vendor(EntityCreateParams.ThirdPartyVerification.Vendor.ALLOY)
                            .build()
                    )
                    .trust(
                        EntityCreateParams.Trust.builder()
                            .address(
                                EntityCreateParams.Trust.Address.builder()
                                    .city("x")
                                    .line1("x")
                                    .state("xx")
                                    .zip("x")
                                    .line2("x")
                                    .build()
                            )
                            .category(EntityCreateParams.Trust.Category.REVOCABLE)
                            .name("x")
                            .addTrustee(
                                EntityCreateParams.Trust.Trustee.builder()
                                    .structure(
                                        EntityCreateParams.Trust.Trustee.Structure.INDIVIDUAL
                                    )
                                    .individual(
                                        EntityCreateParams.Trust.Trustee.Individual.builder()
                                            .address(
                                                EntityCreateParams.Trust.Trustee.Individual.Address
                                                    .builder()
                                                    .city("x")
                                                    .country("x")
                                                    .line1("x")
                                                    .line2("x")
                                                    .state("x")
                                                    .zip("x")
                                                    .build()
                                            )
                                            .dateOfBirth(LocalDate.parse("2019-12-27"))
                                            .identification(
                                                EntityCreateParams.Trust.Trustee.Individual
                                                    .Identification
                                                    .builder()
                                                    .method(
                                                        EntityCreateParams.Trust.Trustee.Individual
                                                            .Identification
                                                            .Method
                                                            .SOCIAL_SECURITY_NUMBER
                                                    )
                                                    .number("xxxx")
                                                    .driversLicense(
                                                        EntityCreateParams.Trust.Trustee.Individual
                                                            .Identification
                                                            .DriversLicense
                                                            .builder()
                                                            .expirationDate(
                                                                LocalDate.parse("2019-12-27")
                                                            )
                                                            .fileId("file_id")
                                                            .state("xx")
                                                            .backFileId("back_file_id")
                                                            .build()
                                                    )
                                                    .other(
                                                        EntityCreateParams.Trust.Trustee.Individual
                                                            .Identification
                                                            .Other
                                                            .builder()
                                                            .country("x")
                                                            .description("x")
                                                            .fileId("file_id")
                                                            .backFileId("back_file_id")
                                                            .expirationDate(
                                                                LocalDate.parse("2019-12-27")
                                                            )
                                                            .build()
                                                    )
                                                    .passport(
                                                        EntityCreateParams.Trust.Trustee.Individual
                                                            .Identification
                                                            .Passport
                                                            .builder()
                                                            .country("x")
                                                            .expirationDate(
                                                                LocalDate.parse("2019-12-27")
                                                            )
                                                            .fileId("file_id")
                                                            .build()
                                                    )
                                                    .build()
                                            )
                                            .name("x")
                                            .confirmedNoUsTaxId(true)
                                            .build()
                                    )
                                    .build()
                            )
                            .formationDocumentFileId("formation_document_file_id")
                            .formationState("x")
                            .grantor(
                                EntityCreateParams.Trust.Grantor.builder()
                                    .address(
                                        EntityCreateParams.Trust.Grantor.Address.builder()
                                            .city("x")
                                            .country("x")
                                            .line1("x")
                                            .line2("x")
                                            .state("x")
                                            .zip("x")
                                            .build()
                                    )
                                    .dateOfBirth(LocalDate.parse("2019-12-27"))
                                    .identification(
                                        EntityCreateParams.Trust.Grantor.Identification.builder()
                                            .method(
                                                EntityCreateParams.Trust.Grantor.Identification
                                                    .Method
                                                    .SOCIAL_SECURITY_NUMBER
                                            )
                                            .number("xxxx")
                                            .driversLicense(
                                                EntityCreateParams.Trust.Grantor.Identification
                                                    .DriversLicense
                                                    .builder()
                                                    .expirationDate(LocalDate.parse("2019-12-27"))
                                                    .fileId("file_id")
                                                    .state("xx")
                                                    .backFileId("back_file_id")
                                                    .build()
                                            )
                                            .other(
                                                EntityCreateParams.Trust.Grantor.Identification
                                                    .Other
                                                    .builder()
                                                    .country("x")
                                                    .description("x")
                                                    .fileId("file_id")
                                                    .backFileId("back_file_id")
                                                    .expirationDate(LocalDate.parse("2019-12-27"))
                                                    .build()
                                            )
                                            .passport(
                                                EntityCreateParams.Trust.Grantor.Identification
                                                    .Passport
                                                    .builder()
                                                    .country("x")
                                                    .expirationDate(LocalDate.parse("2019-12-27"))
                                                    .fileId("file_id")
                                                    .build()
                                            )
                                            .build()
                                    )
                                    .name("x")
                                    .confirmedNoUsTaxId(true)
                                    .build()
                            )
                            .taxIdentifier("x")
                            .build()
                    )
                    .build()
            )

        entity.validate()
    }

    @Test
    fun retrieve() {
        val client =
            IncreaseOkHttpClient.builder()
                .baseUrl(TestServerExtension.BASE_URL)
                .apiKey("My API Key")
                .build()
        val entityService = client.entities()

        val entity = entityService.retrieve("entity_n8y8tnk2p9339ti393yi")

        entity.validate()
    }

    @Test
    fun update() {
        val client =
            IncreaseOkHttpClient.builder()
                .baseUrl(TestServerExtension.BASE_URL)
                .apiKey("My API Key")
                .build()
        val entityService = client.entities()

        val entity =
            entityService.update(
                EntityUpdateParams.builder()
                    .entityId("entity_n8y8tnk2p9339ti393yi")
                    .corporation(
                        EntityUpdateParams.Corporation.builder()
                            .address(
                                EntityUpdateParams.Corporation.Address.builder()
                                    .city("New York")
                                    .country("US")
                                    .line1("33 Liberty Street")
                                    .line2("Unit 2")
                                    .state("NY")
                                    .zip("10045")
                                    .build()
                            )
                            .email("dev@stainless.com")
                            .incorporationState("x")
                            .industryCode("x")
                            .legalIdentifier(
                                EntityUpdateParams.Corporation.LegalIdentifier.builder()
                                    .value("x")
                                    .category(
                                        EntityUpdateParams.Corporation.LegalIdentifier.Category
                                            .US_EMPLOYER_IDENTIFICATION_NUMBER
                                    )
                                    .build()
                            )
                            .name("x")
                            .website("website")
                            .build()
                    )
                    .detailsConfirmedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
                    .governmentAuthority(
                        EntityUpdateParams.GovernmentAuthority.builder()
                            .address(
                                EntityUpdateParams.GovernmentAuthority.Address.builder()
                                    .city("x")
                                    .line1("x")
                                    .state("xx")
                                    .zip("x")
                                    .line2("x")
                                    .build()
                            )
                            .name("x")
                            .build()
                    )
                    .naturalPerson(
                        EntityUpdateParams.NaturalPerson.builder()
                            .address(
                                EntityUpdateParams.NaturalPerson.Address.builder()
                                    .city("x")
                                    .country("x")
                                    .line1("x")
                                    .line2("x")
                                    .state("x")
                                    .zip("x")
                                    .build()
                            )
                            .confirmedNoUsTaxId(true)
                            .identification(
                                EntityUpdateParams.NaturalPerson.Identification.builder()
                                    .method(
                                        EntityUpdateParams.NaturalPerson.Identification.Method
                                            .SOCIAL_SECURITY_NUMBER
                                    )
                                    .number("xxxx")
                                    .driversLicense(
                                        EntityUpdateParams.NaturalPerson.Identification
                                            .DriversLicense
                                            .builder()
                                            .expirationDate(LocalDate.parse("2019-12-27"))
                                            .fileId("file_id")
                                            .state("xx")
                                            .backFileId("back_file_id")
                                            .build()
                                    )
                                    .other(
                                        EntityUpdateParams.NaturalPerson.Identification.Other
                                            .builder()
                                            .country("x")
                                            .description("x")
                                            .fileId("file_id")
                                            .backFileId("back_file_id")
                                            .expirationDate(LocalDate.parse("2019-12-27"))
                                            .build()
                                    )
                                    .passport(
                                        EntityUpdateParams.NaturalPerson.Identification.Passport
                                            .builder()
                                            .country("x")
                                            .expirationDate(LocalDate.parse("2019-12-27"))
                                            .fileId("file_id")
                                            .build()
                                    )
                                    .build()
                            )
                            .name("x")
                            .build()
                    )
                    .riskRating(
                        EntityUpdateParams.RiskRating.builder()
                            .ratedAt(OffsetDateTime.parse("2020-01-31T23:59:59Z"))
                            .rating(EntityUpdateParams.RiskRating.Rating.LOW)
                            .build()
                    )
                    .addTermsAgreement(
                        EntityUpdateParams.TermsAgreement.builder()
                            .agreedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
                            .ipAddress("x")
                            .termsUrl("x")
                            .build()
                    )
                    .thirdPartyVerification(
                        EntityUpdateParams.ThirdPartyVerification.builder()
                            .reference("x")
                            .vendor(EntityUpdateParams.ThirdPartyVerification.Vendor.ALLOY)
                            .build()
                    )
                    .trust(
                        EntityUpdateParams.Trust.builder()
                            .address(
                                EntityUpdateParams.Trust.Address.builder()
                                    .city("x")
                                    .line1("x")
                                    .state("xx")
                                    .zip("x")
                                    .line2("x")
                                    .build()
                            )
                            .name("x")
                            .build()
                    )
                    .build()
            )

        entity.validate()
    }

    @Test
    fun list() {
        val client =
            IncreaseOkHttpClient.builder()
                .baseUrl(TestServerExtension.BASE_URL)
                .apiKey("My API Key")
                .build()
        val entityService = client.entities()

        val page = entityService.list()

        page.response().validate()
    }

    @Test
    fun archive() {
        val client =
            IncreaseOkHttpClient.builder()
                .baseUrl(TestServerExtension.BASE_URL)
                .apiKey("My API Key")
                .build()
        val entityService = client.entities()

        val entity = entityService.archive("entity_n8y8tnk2p9339ti393yi")

        entity.validate()
    }
}
