# Policy renewal

This guide explains how to configure a policy renewal flow in the KASKO webapp framework. Renewal flows allow customers to review and update their policy before accepting a renewal.

## When to Use Renewal

Use a renewal flow when:

* A customer receives a renewal link for an expiring policy.
* You want to preload existing policy data and allow updates.
* The customer needs to explicitly accept the renewal.

## Key Concepts

* **Renewal mode** is enabled via `kdata.config.is_renewal`.
* **Renewal data** is available under the `renewal.*` namespace.
* **Renewal acceptance** is triggered by the `policy-renewal-button` component.

## Required Flags

The framework exposes renewal state via flags:

* `flags.is_renewal` — `true` when a renewal flow is active.

You can use this in JsonLogic to route users to the correct screens.

## Namespaces

Renewal data is available in JsonLogic and content under:

* `renewal.*`
  * `renewal.id` — Renewal ID
  * `renewal.policy` — Original policy data
  * `renewal.quote` — New quote data for renewal

Example:

```json
{ "var": "renewal.quote.gross_payment_amount" }
```

## Enabling Renewal via kdata

Renewal is typically enabled through a renewal link that passes `kdata`:

```json
{
  "config": {
    "is_renewal": true,
    "policy": {
      "id": "policy_xxx"
    }
  }
}
```

This will set `flags.is_renewal` and load the renewal context for the policy.

## Initial Screen Pattern

Use JsonLogic in `config.initial_screen` to route renewal users to a renewal summary screen:

```json
{
  "initial_screen": {
    "type": "jsonlogic",
    "schema": {
      "if": [
        { "var": "flags.is_renewal" },
        "renewal-summary",
        "start"
      ]
    }
  }
}
```

## Typical Renewal Flow

1. Customer opens a renewal link with `is_renewal: true`.
2. The framework loads renewal data and pre-fills inputs.
3. Customer reviews or updates coverage on a renewal screen.
4. Customer clicks `policy-renewal-button` to accept.
5. A renewed policy is created with updated dates.

## Component: policy-renewal-button

Use the `policy-renewal-button` component to trigger renewal acceptance:

```json
{
  "type": "policy-renewal-button",
  "config": {
    "content_key": "flow.renewal.accept"
  }
}
```

Include it in the form footer on the renewal screen along with `error-list`.

## Example Renewal Screen

```json
{
  "path": "renewal-summary",
  "components": [
    {
      "type": "title",
      "config": { "content_key": "flow.renewal.title" }
    },
    {
      "type": "form",
      "config": {
        "components": [
          {
            "type": "summary-panel",
            "config": {
              "content_key": "flow.renewal.summary.title",
              "components": [
                {
                  "type": "summary-panel-row",
                  "config": {
                    "content_key": {
                      "label": "flow.renewal.premium.label",
                      "value": "flow.renewal.premium.value"
                    },
                    "input_field": "data.coverage_type"
                  }
                }
              ]
            }
          }
        ],
        "footer_components": [
          { "type": "error-list" },
          { "type": "button-back" },
          {
            "type": "policy-renewal-button",
            "config": { "content_key": "flow.renewal.accept" }
          }
        ]
      }
    }
  ],
  "next": "success"
}
```

## Content Keys

Example content keys you might add to translations:

```csv
"flow.renewal.title","Review your renewal"
"flow.renewal.summary.title","Renewal summary"
"flow.renewal.premium.label","Premium"
"flow.renewal.premium.value","{renewal.quote.gross_payment_amount, asCurrency}"
"flow.renewal.accept","Accept renewal"
```

## Notes

* Make sure any renewal-specific fields are enabled in your manifest request configuration.
* If you use `required_requests` on the success screen, include the relevant request types for your renewal flow.
* Use `flags.is_renewal` to gate any renewal-only UI.
