# UpdateCompany

## Permission Scope

company

## Overview

UpdateCompany modifies fields on an existing company. Updatable fields include legal name, tax identification number, registration number, registered address fields, and base currency (only while in DRAFT status). Base currency becomes immutable after activation.

This command supports company configuration during DRAFT setup and ongoing maintenance of company details.

## Business Rules

- Company must exist
- Legal name, if provided, must be non-empty
- Base currency can only be changed while company is in DRAFT status
- Base currency, if provided, must reference a valid active Currency from the primitives module
- Address fields can be updated in any status (DRAFT, ACTIVE, INACTIVE)
- Tax ID and registration number can be updated in any status

## Process Flow

```mermaid
flowchart TD
    A[Receive update request] --> B{Company exists?}
    B -->|No| C[Return error: COMPANY_NOT_FOUND]
    B -->|Yes| D{Legal name provided and empty?}
    D -->|Yes| E[Return error: INVALID_LEGAL_NAME]
    D -->|No| F{Base currency change requested?}
    F -->|Yes| G{Company in DRAFT?}
    G -->|No| H[Return error: CURRENCY_IMMUTABLE]
    G -->|Yes| I{Currency exists and active?}
    I -->|No| J[Return error: CURRENCY_NOT_FOUND]
    I -->|Yes| K[Update company record]
    F -->|No| K
    K --> L[Return updated company]
```

## External Dependencies

- [primitives::getCurrency](../../../primitives/docs/query/GetCurrency.md) - Validates that the referenced base currency exists and is active

## Error Scenarios

- **COMPANY_NOT_FOUND**: Specified company ID does not exist
- **INVALID_LEGAL_NAME**: Legal name is empty, whitespace-only, or not provided
- **CURRENCY_IMMUTABLE**: Attempted to change base currency on a non-DRAFT company
- **CURRENCY_NOT_FOUND**: Referenced base currency does not exist or is inactive

## Test Cases

- updates legal name on DRAFT company
- updates address fields on ACTIVE company
- updates tax ID and registration number
- returns error when company does not exist
- returns error when legal name is empty
- returns error when changing base currency on ACTIVE company
- returns error when changing base currency on INACTIVE company
- returns error when new base currency does not exist
- returns error when new base currency is inactive
- updates base currency on DRAFT company
