# ListInternalOrders

## Overview

ListInternalOrders retrieves a list of internal order records matching optional filter criteria. Callers can filter by companyId, orderType (OVERHEAD, INVESTMENT, ACCRUAL), status (CREATED, RELEASED, TECHNICALLY_COMPLETED, CLOSED), and costCenterId to find orders assigned to a specific responsible cost center. This query supports internal order browsing, project portfolio review, and cost posting target selection.

## Business Rules

- Accepts optional filter parameters: `{ companyId, orderType, status, costCenterId }`
- Returns a list of internal orders matching all provided filters (AND logic)
- When no filters are provided, returns all internal orders accessible to the caller
- Each returned internal order includes all header fields, responsible cost center reference, and budget assignment
- Returns an empty list if no internal orders match the given filters
- Results are scoped to the caller's accessible companies

## Process Flow

```mermaid
flowchart TD
    A[Receive input with optional filters] --> B[Build query with provided filters]
    B --> C{companyId provided?}
    C -->|Yes| D[Add companyId filter]
    C -->|No| E[Skip companyId filter]
    D --> F{orderType provided?}
    E --> F
    F -->|Yes| G[Add orderType filter]
    F -->|No| H[Skip orderType filter]
    G --> I{status provided?}
    H --> I
    I -->|Yes| J[Add status filter]
    I -->|No| K[Skip status filter]
    J --> L{costCenterId provided?}
    K --> L
    L -->|Yes| M[Add costCenterId filter]
    L -->|No| N[Skip costCenterId filter]
    M --> O[Execute query]
    N --> O
    O --> P[Return list of matching internal orders]
```

## External Dependencies

- None

## Error Scenarios

- **INVALID_ORDER_TYPE_FILTER**: Provided orderType value is not OVERHEAD, INVESTMENT, or ACCRUAL
- **INVALID_STATUS_FILTER**: Provided status value is not CREATED, RELEASED, TECHNICALLY_COMPLETED, or CLOSED
- **COST_CENTER_NOT_FOUND**: Provided costCenterId does not reference an existing cost center

## Test Cases

- returns all internal orders when no filters are provided
- returns internal orders filtered by companyId
- returns internal orders filtered by orderType OVERHEAD
- returns internal orders filtered by status RELEASED
- returns internal orders filtered by costCenterId
- returns internal orders matching multiple filters simultaneously
- returns an empty list when no internal orders match the given filters
- returns error when orderType filter is invalid
- returns error when status filter is invalid
- returns error when costCenterId does not exist
