# ListAccountingPeriods

## Overview

ListAccountingPeriods retrieves a list of accounting periods for a given company or fiscal year, with optional filters for status and period type. Results are sorted by startDate ascending. This query supports period navigation, close workflow coordination, and upstream module posting validation.

## Business Rules

- At least one scoping parameter is required: `companyId` or `fiscalYearId`
- Optional filters:
  - `status` — filter by period status (NEVER_OPENED, FUTURE_ENTERABLE, OPEN, CLOSED, PERMANENTLY_CLOSED)
  - `periodType` — filter by period type (OPERATING, ADJUSTMENT)
- All filters can be combined; when multiple filters are provided, results must match all criteria (AND logic)
- Returns full accounting period records (same shape as GetAccountingPeriod output)
- Results are sorted by startDate ascending
- Returns an empty list if no periods match the filters

## Process Flow

```mermaid
flowchart TD
    A[Receive input with companyId or fiscalYearId] --> B[Build query with scope]
    B --> C{Filters provided?}
    C -->|Yes| D[Apply status and/or periodType filters]
    C -->|No| E[Return all periods in scope]
    D --> E
    E --> F[Sort by startDate ascending]
    F --> G[Return period list]
```

## External Dependencies

- None

## Error Scenarios

- **EMPTY_RESULT**: No records match the given criteria

## Test Cases

- returns error when neither companyId nor fiscalYearId is provided
- returns all accounting periods for a company
- returns accounting periods filtered by fiscal year
- returns accounting periods filtered by status
- returns accounting periods filtered by period type
- returns empty list when no accounting periods match
