export type TelegramApiResponse<T = unknown> =
  | { ok: true; result: T }
  | { ok: false; error_code: number; description: string; parameters?: { retry_after?: number } };

export function telegramOk<T>(result: T): TelegramApiResponse<T> {
  return { ok: true, result };
}

export function telegramError(
  errorCode: number,
  description: string,
  parameters?: { retry_after?: number }
): TelegramApiResponse<never> {
  return parameters ? { ok: false, error_code: errorCode, description, parameters } : { ok: false, error_code: errorCode, description };
}

export function serializeTelegramResponse(response: TelegramApiResponse) {
  return JSON.stringify(response);
}
