/**
 * Constant object defining the possible states of an asynchronous operation.
 * Used as a type-safe alternative to string literals for status values.
 */
export const AsyncResultStatus = {
  Idle: 'Idle',
  Pending: 'Pending',
  Success: 'Success',
  Error: 'Error',
} as const;

export type AsyncResultStatus =
  (typeof AsyncResultStatus)[keyof typeof AsyncResultStatus];

/**
 * Generic interface representing the state of an asynchronous operation.
 * Combines status tracking with optional data and error information.
 *
 * @template T - The type of data returned on successful operations
 */
export interface AsyncResult<T> {
  /**
   * Current status of the asynchronous operation
   */
  status: AsyncResultStatus;

  /**
   * Data returned by a successful operation
   * Only defined when status is Success
   */
  data?: T;

  /**
   * Error information from a failed operation
   * Only defined when status is Error
   */
  error?: unknown;
}
