# Legal Documents

## getLegalDocuments

Fetches a collection of currently active legal documents.

Optional `languageTag`  language tag (e.g., "en", "fr-CA"). If null or blank, the backend default localization is applied.

#### Parameters:

* `userProfileId`: The ID is available in activation or user call

### Concrete Example

{% tabs %}
{% tab title="Swift" %}

```swift
let service = LegalDocumentsService()
service.getLegalDocuments(
    userProfileId: userProfileId,
    then: { result in
        switch result {
        case: .success(_)
            // successfully retrieved
        case: .failure(_)
            // failure error
        }
})
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val service = LegalDocumentsService()
service.getLegalDocuments(userProfileId) { result: Result<List<LegalDocumentsCollection>> ->
    if (result?.value == null || result.throwable != null) {
        // failure
    } else {
        // Success
        val content = result.value
    }
})
```

{% endtab %}
{% endtabs %}

## getLegalDocumentContent

Fetches the full content for a specific legal document.

#### Parameters:

* `documentId`: The document ID that is available in the previous call. (when the list of documents is fetched)
* `userProfileId`: The ID is available in activation or user call

To get the specific legal document, first host app needs to retrieve the `documentId` provided when the `getLegalDocuments` API call is made and need to provide the retrieved `documentId` as an argument to `submitConsent` API

### Concrete Example

{% tabs %}
{% tab title="Swift" %}

```swift
let service = LegalDocumentsService()
service.getLegalDocumentContent(
    userProfileId: String,
    documentId: String,
    ) { result in
        switch result {
        case: .success(_)
            // successfully updated
        case: .failure(_)
            // failure error
        }
    }
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val service = LegalDocumentsService()
service.getLegalDocumentContent(
    userProfileId,
    documentId
    ) { result: Result<LegalDocumentContent> ->
        if (result?.value == null || result.throwable != null) {
            // failure
        } else {
            // Success
            val content = result.value
        }
    }
```

{% endtab %}
{% endtabs %}

## submitConsent

Submits user consent for a specific legal document.

#### Parameters:

* `documentId`: The document ID that is available in the previous call. (when the list of documents is fetched)
* `userProfileId`: The ID is available in activation or user call

To submit the user consent, first host app needs to retrieve the `documentId` provided when the `getLegalDocuments` API call is made and need to provide the retrieved `documentId` as an argument to `submitConsent` API

### Concrete Example

{% tabs %}
{% tab title="Swift" %}

<pre class="language-swift"><code class="lang-swift">let service = LegalDocumentsService()
<strong>service.submitConsent(for userProfileId: String, documentId: String) { result in
</strong>        switch result {
        case: .success(_)
            // successfully updated
        case: .failure(_)
            // failure error
        }
    })
</code></pre>

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val service = LegalDocumentsService()
service.submitConsent(
    userProfileId,
    documentId
    ) { result: Result<LegalDocumentsAccept> ->
    if (result?.value == null || result.throwable != null) {
        // failure
    } else {
        // Success
        val content = result.value
    }
}
```

{% endtab %}
{% endtabs %}
