
    j                         d Z ddlmZ ddlmZmZmZmZ ddlm	Z	m
Z
 ddlmZ ddlmZ  ede      Z ed	e
      ZddgZ G d de
eef         Z G d de
eef         Zy)z"Pagination wrapper for Honcho SDK.    )annotations)AsyncIterator	AwaitableCallableIterator)AnyGeneric)	BaseModel)TypeVarT)boundU)defaultSyncPage	AsyncPagec                      e Zd ZdZ	 	 d	 	 	 	 	 	 	 	 	 ddZddZddZddZedd       Z	edd       Z
edd	       Zedd
       Zedd       ZddZddZy)r   z
    Paginated result wrapper that transforms objects from type T to type U.

    Provides iteration and transformation capabilities for paginated API responses.
    Nc                    || _         || _        || _        || _        |j	                  dg       }|D cg c]  }|j                  |       c}| _        yc c}w )a  
        Initialize the page.

        Args:
            data: Raw paginated response data with items, page, size, total, pages
            item_type: Type to parse items as
            transform_func: Optional function to transform objects from type T to type U.
                            If None, objects are passed through unchanged.
            fetch_next: Optional callback to fetch the next page. Takes page number.
        itemsN_data
_item_type_transform_func_fetch_nextgetmodel_validate
_raw_itemsselfdata	item_typetransform_func
fetch_next	raw_itemsitems          /home/cube/projects/richard/traning coach/.omo/evidence/nutricoach-v150-combined/st_01a0560c-r63-installed-wheel-first-claim-qa/venv/lib/python3.12/site-packages/honcho/pagination.py__init__zSyncPage.__init__   s_    " &*
#,8FEO HHWb)	7@$
7@tI$$T*y$
 $
   Ac              #     K   | }|I|j                   D ]&  }| j                  | j                  |       #| ( |j                         }|Hyyw)aA  
        Iterate over all transformed items across all pages.

        Warning:
            This iterator automatically fetches ALL subsequent pages as you iterate.
            For large datasets, this may result in many API calls. If you only need
            the current page, use the `items` property instead.
        Nr   r   get_next_pager   pager$   s      r%   __iter__zSyncPage.__iter__4   s[      '+''3..t44J	 (
 %%'D s   AAAc                ^    | j                   |   }| j                  | j                  |      S |S z4Get a transformed item by index on the current page.r   r   r   indexr$   s      r%   __getitem__zSyncPage.__getitem__F   2    u%+''--    c                ,    t        | j                        S z,Get the number of items on the current page.lenr   r   s    r%   __len__zSyncPage.__len__M       4??##r5   c                    | j                   )| j                  D cg c]  }| j                  |       c}S t        | j                        S c c}w z.Get all transformed items on the current page.r   r   listr   r$   s     r%   r   zSyncPage.itemsQ   I     +;???K?4D((.?KKDOO$$ L   Ac                8    | j                   j                  d      S z/Get the total number of items across all pages.totalr   r   r:   s    r%   rF   zSyncPage.totalX        zz~~g&&r5   c                8    | j                   j                  d      S zGet the current page number.r,   rG   r:   s    r%   r,   zSyncPage.page]        zz~~f%%r5   c                8    | j                   j                  d      S zGet the page size.sizerG   r:   s    r%   rN   zSyncPage.sizeb   rK   r5   c                8    | j                   j                  d      S zGet the total number of pages.pagesrG   r:   s    r%   rQ   zSyncPage.pagesg   rH   r5   c                F    | j                   }| j                  }||y||k  S zCheck if there's a next page.Fr,   rQ   r   current_pagetotal_pagess      r%   has_next_pagezSyncPage.has_next_pagel   -    yyjj;#6k))r5   c                    | j                         sy| j                  y| j                  }|y| j                  |dz         S zx
        Fetch the next page of results.

        Returns None if there are no more pages or no fetch callback.
        N   rX   r   r,   r   rV   s     r%   r*   zSyncPage.get_next_paget   sJ     !!##yyq 011r5   NN)
r   dict[str, Any]r    type[T]r!   Callable[[T], U] | Noner"   z(Callable[[int], 'SyncPage[T, U]'] | NonereturnNone)rc   zIterator[U] | Iterator[T]r2   intrc   zU | Trc   rf   rc   zlist[U] | list[T]rc   z
int | Nonerc   bool)rc   z'SyncPage[T, U] | None')__name__
__module____qualname____doc__r&   r-   r3   r;   propertyr   rF   r,   rN   rQ   rX   r*    r5   r%   r   r      s     37?C

 
 0	

 =
 

8($$ % % ' ' & & & & ' '*2r5   c                      e Zd ZdZ	 	 d	 	 	 	 	 	 	 	 	 ddZddZddZddZedd       Z	edd       Z
edd	       Zedd
       Zedd       ZddZddZy)r   z
    Async paginated result wrapper that transforms objects from type T to type U.

    Provides async iteration and transformation capabilities for paginated API responses.
    Nc                    || _         || _        || _        || _        |j	                  dg       }|D cg c]  }|j                  |       c}| _        yc c}w )a  
        Initialize the async page.

        Args:
            data: Raw paginated response data with items, page, size, total, pages
            item_type: Type to parse items as
            transform_func: Optional function to transform objects from type T to type U.
                            If None, objects are passed through unchanged.
            fetch_next: Optional async callback to fetch the next page. Takes page number.
        r   Nr   r   s          r%   r&   zAsyncPage.__init__   sb    " &*
#,8F 	
 HHWb)	7@$
7@tI$$T*y$
 $
r'   c                  K   | }|S|j                   D ](  }| j                  | j                  |       $| * |j                          d{   }|Ryy7 	w)aG  
        Async iterate over all transformed items across all pages.

        Warning:
            This iterator automatically fetches ALL subsequent pages as you iterate.
            For large datasets, this may result in many API calls. If you only need
            the current page, use the `items` property instead.
        Nr)   r+   s      r%   	__aiter__zAsyncPage.__aiter__   sc      (,''3..t44J	 (
 ++--D  .s   AAAAAc                ^    | j                   |   }| j                  | j                  |      S |S r/   r0   r1   s      r%   r3   zAsyncPage.__getitem__   r4   r5   c                ,    t        | j                        S r7   r8   r:   s    r%   r;   zAsyncPage.__len__   r<   r5   c                    | j                   )| j                  D cg c]  }| j                  |       c}S t        | j                        S c c}w r>   r?   rA   s     r%   r   zAsyncPage.items   rB   rC   c                8    | j                   j                  d      S rE   rG   r:   s    r%   rF   zAsyncPage.total   rH   r5   c                8    | j                   j                  d      S rJ   rG   r:   s    r%   r,   zAsyncPage.page   rK   r5   c                8    | j                   j                  d      S rM   rG   r:   s    r%   rN   zAsyncPage.size   rK   r5   c                8    | j                   j                  d      S rP   rG   r:   s    r%   rQ   zAsyncPage.pages   rH   r5   c                F    | j                   }| j                  }||y||k  S rS   rT   rU   s      r%   rX   zAsyncPage.has_next_page   rY   r5   c                   K   | j                         sy| j                  y| j                  }|y| j                  |dz          d{   S 7 wr[   r]   r^   s     r%   r*   zAsyncPage.get_next_page   sT      !!##yy%%lQ&67777s   AAAAr_   )
r   r`   r    ra   r!   rb   r"   z4Callable[[int], Awaitable['AsyncPage[T, U]']] | Nonerc   rd   )rc   z#AsyncIterator[U] | AsyncIterator[T]re   rg   rh   ri   rj   )rc   z'AsyncPage[T, U] | None')rl   rm   rn   ro   r&   ru   r3   r;   rp   r   rF   r,   rN   rQ   rX   r*   rq   r5   r%   r   r      s     37KO

 
 0	

 I
 

<.$$ % % ' ' & & & & ' '*8r5   N)ro   
__future__r   collections.abcr   r   r   r   typingr   r	   pydanticr
   typing_extensionsr   r   r   __all__r   r   rq   r5   r%   <module>r      si    ( " H H   %Cy!C{
#r2wq!t} r2jt81 t8r5   