# Driving Summary

The SDK allows for the host application to retrieve driving summary data.

### Fetch Drive Summary

To fetch driving summary data, the following API can be used.

### Concrete example

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

```swift
let service = DrivingSummaryService()
let startDate = Date() // customize this to your convenience
let endDate = Date() // customize this to your convenience

service.fetch(filters: [.date(start: startDate, end: endDate)], then: { result in 
    guard !result.value.isEmpty else {
        // failure
        return
    }
    completionHandler(.success(result.value))
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val drivingSummaryService = DrivingSummaryService()
val filters: MutableSet<DrivingSummaryService.Filter> = HashSet()
filters.add(DrivingSummaryService.Filter.Date(summaryStartDate, summaryEndDate))

drivingSummaryService.fetchDrivingSummaryAggregate {filters)
            { result: Result<Content?>? ->
                if (result?.value == null || result.throwable != null) {
                    // failure
                    } else {
                        // Success
                        val content = result.value
                }
})
```

{% endtab %}
{% endtabs %}

### Fetch Drive Summary By Policy

To fetch driving summary for a specific policy within the given start and end date, the following API can be used.

#### Parameters:

* **`policyId`**: The policy ID
* **`startDate`**: Start date (optional)
* **`endDate`**: End date (optional)
* **`verificationCutOffDate`**: Verification cutoff date (optional)

### Concrete example

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

```swift
let service = DrivingSummaryService()
service.fetchByPolicy(policyId: policyId,
                       startDate: startDate,
                       endDate: endDate,
                       verificationCutOffDate: verificationCutOffDate) { result in
    switch result {
    case .success(let policyDrivingSummary):
        // Success - use policyDrivingSummary
    case .failure(let error):
        // Handle error
    }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val service = DrivingSummaryService()
service.fetchByPolicy(policyId,
                       startDate,
                       endDate,
                       verificationCutOffDate) { result: Result<PolicyDrivingSummary>? ->
    if (result?.value == null || result.throwable != null) {
        // failure
    } else {
        // Success
        val policyDrivingSummary = result.value
    }
```

{% endtab %}
{% endtabs %}

### Fetch Drive Summary For User By Policy

To fetch driving summary for a specific user and policy within the given start and end date, the following API can be used.

#### Parameters:

* **`userId`**: The user ID
* **`policyId`**: The policy ID
* **`startDate`**: Start date (optional)
* **`endDate`**: End date (optional)
* **`verificationCutOffDate`**: Verification cutoff date (optional)

### Concrete example

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

```swift
let service = DrivingSummaryService()
service.fetchForUserByPolicy(userId: userId,
                              policyId: policyId,
                              startDate: startDate,
                              endDate: endDate,
                              verificationCutOffDate: verificationCutOffDate) { result in
    switch result {
    case .success(let userDrivingSummary):
        // Success - use userDrivingSummary
    case .failure(let error):
        // Handle error
    }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val service = DrivingSummaryService()
service.fetchForUserByPolicy(userId,
                              policyId,
                              startDate,
                              endDate,
                              verificationCutOffDate) { result: Result<UserDrivingSummary>? ->
    if (result?.value == null || result.throwable != null) {
        // failure
    } else {
        // Success
        val userDrivingSummary = result.value
    }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sdk.ims.tech/drivesync-portal/driving-summary.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
