# W-UNKN Rule Implementation

## Overview
This document describes the implementation of the W-UNKN (Value set to unknown) validation rule. 
The rule raises a warning when a field’s value equals that field’s configured “unknown” label (e.g. 9, 99, 9999) as defined in the schema.

## Rule Description
**Rule Code**: W-UNKN  
**Rule Type**: WARNING  
**Description**: Value set to missing
**Rule Definition ID**: 67  
**Validation Message ID**: 66  

### Rule Logic
The W-UNKN message is produced when:
- For each record, the rule evaluates one or more fields (depending on configuration).
- If the field’s value equals the field’s **unknown label** (schema `Field.unknownValue` / `getUnknownLabel()`), a warning is raised for that field.
- Empty/blank values are ignored (no warning).
- Fields with no unknown label configured are skipped.

### Configuration (ruleToField only)
W-UNKN is configured via ruleToField

**2** (ALL_FIELDS) | Check all fields in the schema | Every field that has a non-empty unknown label is checked; W-UNKN is raised when value equals that label. |
**3** (SOME_FIELDS) | Check only listed fields | Only the fields explicitly listed in `ruletofield` (by `field_id`) for this rule and protocol are checked. |

For a given protocol and rule 67, use either ALL_FIELDS or SOME_FIELDS, not both.
If both target_id 2 and 3 rows exist, the rule receives an inconsistent target and is skipped.

## Implementation Files

### 1. Java Implementation
**File**: `src/main/java/eu/europa/ec/jrc/qcs/engine/rule/field/UnknownValueRule.java`


Migration from legacy `FIELD.mandatory=3` to ruleToField (SOME_FIELDS) is described in:
`docs/migration/deprecate-mandatory-3-w-unkn-ruletofield.sql`.

## Testing

