import {Meta} from '@storybook/addon-docs/blocks'

<Meta title='@dxtmisha/en/functional-basic/Classes/ApiStatus - API Status Management'/>

# ApiStatus Class

A class dedicated to tracking and managing the state of an API request. It securely holds the current HTTP status, error messages, and the parsed response body, allowing applications to react to real-time changes utilizing state abstractions.

> `ApiStatus` is an **auxiliary class**, designed for tracking request states. In most cases, it is recommended to interact with request status through the `status` property of the `ApiInstance` result or the global `Api` execution flow.

## Key Features

- **Centralized State** — holds everything related to the result of an API call: HTTP status, custom texts, raw response data, and generated messages.
- **Chainable API** — setters return `this`, allowing multiple state changes to be chained elegantly.
- **Automatic Message Extraction** — intelligently attempts to parse and pull human-readable `message` fields directly from structured server responses.

## Methods

### Action

- `getResponse<T>(): T | undefined` — Returns the raw data payload from the last successful request.
- `getMessage(): string` — Returns the server message pulled from a successful response or a manually set message.

### Check

- `get(): ApiStatusItem | undefined` — Returns the complete status data object.
- `getStatus(): number | undefined` — Returns the HTTP status code (e.g., `200`).
- `getStatusText(): string | undefined` — Returns the status text (e.g., `"OK"`).
- `getStatusType(): ApiStatusType | undefined` — Returns the last status validation type.
- `getError(): string | undefined` — Returns the recorded error message.

### Configuration

- `set(data: ApiStatusItem): this` — Sets multiple status fields at once.
- `setStatus(status?: number, statusText?: string): this` — Sets the HTTP status code and text.
- `setError(error?: string): this` — Records an error message string.
- `setLastResponse(response?: any): this` — Records a server response and automatically extracts `message` and `status` if present.
- `setLastStatus(status?: ApiStatusType): this` — Sets the custom API status type.
- `setLastMessage(message?: string): this` — Explicitly records a message.

## Types

#### `ApiStatusItem`
A complete representation of a request status.
- `status?: number` — HTTP status code.
- `statusText?: string` — HTTP status text.
- `error?: string` — Error message.
- `lastResponse?: any` — Last response data.
- `lastStatus?: ApiStatusType` — Last status type.
- `lastMessage?: string` — Last message.
