# UpdateAccount

## Permission Scope

accountManagement

## Overview

updateAccount modifies the core fields of an existing GL account: code, name, and account type.

## Business Rules

- Target account must exist
- Name, when provided, must be non-empty
- Account code, when changed, must be numeric
- Account code, when changed, must remain unique within the company
- Account type, when provided, must be ASSET, LIABILITY, EQUITY, REVENUE, or EXPENSE

## Process Flow

```mermaid
flowchart TD
    A[Receive update request] --> B{Account exists?}
    B -->|No| C[Return not found]
    B -->|Yes| F{Changes valid?}
    F -->|No| G[Return validation error]
    F -->|Yes| H[Apply update]
    H --> I[Return account]
```

## External Dependencies

- None

## Error Scenarios

- **ACCOUNT_NOT_FOUND**: Specified account ID does not exist
- **NAME_REQUIRED**: Name is empty, whitespace-only, or not provided
- **INVALID_ACCOUNT_CODE**: Account code is not a valid numeric identifier
- **DUPLICATE_ACCOUNT_CODE**: An account with the same code already exists in the company

## Test Cases

- returns error when account does not exist
- returns error when name is empty
- returns error when changed code is not numeric
- returns error when changed code duplicates another account
- updates name, code, and account type
- returns existing account when no changes are provided
