# ActivateCompany

## Permission Scope

company

## Overview

ActivateCompany transitions a company from DRAFT to ACTIVE status, making it available for transactional modules to reference. All required fields must be configured before activation: legal name, base currency, and registered address.

This command supports the go-live workflow where companies are fully configured before becoming operational.

## Business Rules

- Company must exist
- Company must be in DRAFT status
- Legal name must be non-empty
- Base currency must be assigned and reference a valid active Currency
- Registered address fields (street, city, postalCode, country) must be populated; state/province is optional
- After activation, base currency becomes immutable

## Process Flow

```mermaid
flowchart TD
    A[Receive activate request] --> B{Company exists?}
    B -->|No| C[Return error: COMPANY_NOT_FOUND]
    B -->|Yes| D{Company in DRAFT?}
    D -->|No| E[Return error: INVALID_STATE]
    D -->|Yes| F{Legal name set?}
    F -->|No| G[Return error: MISSING_REQUIRED_FIELDS]
    F -->|Yes| H{Base currency assigned?}
    H -->|No| G
    H -->|Yes| I{Currency valid and active?}
    I -->|No| L[Return error: INVALID_BASE_CURRENCY]
    I -->|Yes| J{Address complete?}
    J -->|No| G
    J -->|Yes| K[Set status: ACTIVE]
    K --> M[Return activated company]
```

## External Dependencies

- **primitives module — Currency**: The referenced base currency must exist and be in active status in the primitives module's Currency entity

## Error Scenarios

- **COMPANY_NOT_FOUND**: Specified company ID does not exist
- **INVALID_STATE**: Target entity is not in a valid status for this operation
- **MISSING_REQUIRED_FIELDS**: One or more required fields are missing or empty
- **INVALID_BASE_CURRENCY**: The assigned base currency does not exist or is not in active status in the primitives module

## Test Cases

- activates DRAFT company with all required fields
- throws when company does not exist
- throws when company is already ACTIVE
- throws when company is INACTIVE
- throws when legal name is missing
- throws when base currency is not assigned
- throws when base currency references a non-existent Currency
- throws when base currency references an inactive Currency
- throws when address street is missing
- throws when address city is missing
- throws when address postalCode is missing
- throws when address country is missing
