# Government Validation

The Government Validation module validates identity data extracted from a user's ID against an authoritative government registry. The process runs in the background and isn't visible to the user. It can also match the user's photo in the government database against their captured selfie. Whether the validation runs and what it checks also depend on your Incode Flow or Workflow configuration.

For an overview of this module and how it works, see [Government Data Verification](https://developer.incode.com/docs/government-data-verification) and [Government Record Verification](https://developer.incode.com/docs/government-record-verification).

How you use this module depends on your [integration pattern](https://developer.incode.com/docs/android-common-implementation-patterns#integration-patterns). In Patterns 1 and 2, you add the module to a `FlowConfig` in code as shown on this page. In Pattern 3, you define your modules and configuration in Dashboard as a Flow or Workflow and reference it by ID with `startFlow()` or `startWorkflow()` as shown on [Run Flows Configured in Dashboard](https://developer.incode.com/docs/android-run-flows-configured-online).

Government Validation is not available in [Capture-Only mode](https://developer.incode.com/docs/android-capture-only-sdk); adding it there throws `ModuleNotAvailableException`.

## Add Government Validation

1. Add an [ID Scan](https://developer.incode.com/docs/android-id-scan) or [QR Scan](https://developer.incode.com/docs/android-qr-scan) module, and a [Selfie Scan](https://developer.incode.com/docs/android-selfie-scan) module, before Government Validation. Government Validation depends on these earlier capture steps so there is document data and a face to validate.
2. Add the module with one of the `addGovernmentValidation` overloads:

   ```kotlin
   // Default configuration
   flowConfigBuilder.addGovernmentValidation()

   // Custom configuration
   flowConfigBuilder.addGovernmentValidation(governmentValidation)
   ```
   ```java
   // Default configuration
   flowConfigBuilder.addGovernmentValidation();

   // Custom configuration
   flowConfigBuilder.addGovernmentValidation(governmentValidation);
   ```

### Example

The example below adds ID Scan and Selfie Scan before Government Validation, builds a `GovernmentValidation` module with the animation shown, and listens for the result through `onGovernmentValidationCompleted()`.

```kotlin
val governmentValidation = GovernmentValidation.Builder()
    .setSkipAnimation(false)
    .build()

val flowConfig = FlowConfig.Builder()
    .addID()
    .addSelfieScan()
    .addGovernmentValidation(governmentValidation)
    .build()

val onboardingListener = object : IncodeWelcome.OnboardingListener() {
    override fun onGovernmentValidationCompleted(success: Boolean) {
        // Government validation completed; success indicates whether it passed
    }

    override fun onError(error: Throwable) {
        // Onboarding flow was aborted due to error
    }
}

IncodeWelcome.getInstance().startOnboarding(
    activityContext,
    sessionConfig,
    flowConfig,
    onboardingListener
)
```
```java
GovernmentValidation governmentValidation = new GovernmentValidation.Builder()
    .setSkipAnimation(false)
    .build();

FlowConfig flowConfig = new FlowConfig.Builder()
    .addID()
    .addSelfieScan()
    .addGovernmentValidation(governmentValidation)
    .build();

IncodeWelcome.OnboardingListener onboardingListener = new IncodeWelcome.OnboardingListener() {
    @Override
    public void onGovernmentValidationCompleted(boolean success) {
        // Government validation completed; success indicates whether it passed
    }

    @Override
    public void onError(@NonNull Throwable error) {
        // Onboarding flow was aborted due to error
    }
};

IncodeWelcome.getInstance().startOnboarding(
    activityContext,
    sessionConfig,
    flowConfig,
    onboardingListener
);
```

## Configuration Options

Configure the module with `GovernmentValidation.Builder`. The table below lists the one option it exposes.

| Setting            | Description                                                                                                             |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------- |
| `setSkipAnimation` | Sets whether the animation that plays in this module is skipped. `true` skips it, `false` plays it. Default is `false`. |

For the complete option set, see `GovernmentValidation.Builder` in [API Reference](https://developer.incode.com/docs/android-api-reference).

## Result

Government Validation does not return a result payload object to the integrator. The flow signals completion through the `onGovernmentValidationCompleted(success)` callback on `OnboardingListener`. Key fields include:

- `isSuccess`: `true` if government validation completed successfully; otherwise, `false`.
- Fields inherited from `BaseResult`:
  - `resultCode`: The `ResultCode` for this result.
  - `error`: When `resultCode` is `ERROR`, the `Throwable` that caused it; otherwise, `null`.
  - `deviceStats`: The `DeviceStats` snapshot of the device state when the result was produced.
  - `motionStatus`: Device motion assessment during capture. One of the following:
    - `UNCLEAR`: Motion could not be determined; the default.
    - `PASS`: Device motion was within acceptable limits.
    - `FAIL`: Excessive device motion was detected.

Errors are not delivered through this callback. If the flow is aborted, for example due to a network failure or an unavailable module, the error surfaces via `OnboardingListener.onError(Throwable)`. There is no module-specific exception subtype for Government Validation.

For the related API surface, see `GovernmentValidation` in [API Reference](https://developer.incode.com/docs/android-api-reference).
