# CreatePartnerIdentification

## Permission Scope

partnerDetail

## Overview

createPartnerIdentification adds an identification document or number to a business partner. Identifications represent external references such as tax IDs, registration numbers, or government-issued identifiers. The combination of type and value must be unique within the company scope to prevent duplicate registrations. Identifications can be added regardless of the partner's lifecycle status (DRAFT, ACTIVE, or INACTIVE).

## Business Rules

- Partner must exist in the system
- Partner status is not checked — identifications can be added in any lifecycle state (DRAFT, ACTIVE, or INACTIVE)
- Value is required and must be non-empty
- The combination of (type, value) must be unique within the company scope
- When both validFrom and validTo are provided, validTo must be greater than or equal to validFrom
- Issuing country, validFrom, and validTo are optional

## Process Flow

```mermaid
flowchart TD
    A[Receive create request] --> B{Partner exists?}
    B -->|No| C[Return error: partner not found]
    B -->|Yes| D2{Value non-empty?}
    D2 -->|No| D3[Return error: invalid value]
    D2 -->|Yes| F{type + value unique in company?}
    F -->|No| G[Return error: duplicate identification]
    F -->|Yes| H{Both validFrom and validTo provided?}
    H -->|Yes| I{validTo >= validFrom?}
    I -->|No| J[Return error: invalid validity period]
    I -->|Yes| K[Create identification record]
    H -->|No| K
    K --> L[Return created identification]
```

## External Dependencies

- None

## Error Scenarios

- **PARTNER_NOT_FOUND**: Specified partner ID does not exist
- **INVALID_VALUE**: Value is empty, whitespace-only, or not provided
- **DUPLICATE_IDENTIFICATION**: An identification with the same (type, value) combination already exists within the company
- **INVALID_VALIDITY_PERIOD**: validTo is earlier than validFrom

## Test Cases

- creates identification for partner
- creates identification for DRAFT partner
- creates identification for INACTIVE partner
- returns error when partner not found
- returns error when value is empty
- returns error when duplicate (type, value) in company
- returns error when validTo is before validFrom
- creates with optional fields omitted
