99from typing import Self
1010
1111# pylint: disable=no-name-in-module
12- from frequenz .api .common .v1 .pagination .pagination_info_pb2 import PaginationInfo
13- from frequenz .api .common .v1 .pagination .pagination_params_pb2 import PaginationParams
12+ from frequenz .api .common .v1 .pagination .pagination_info_pb2 import (
13+ PaginationInfo as PBPaginationInfo ,
14+ )
15+ from frequenz .api .common .v1 .pagination .pagination_params_pb2 import (
16+ PaginationParams as PBPaginationParams ,
17+ )
18+ from frequenz .api .common .v1alpha8 .pagination .pagination_info_pb2 import (
19+ PaginationInfo as PBPaginationInfoAlpha8 ,
20+ )
21+ from frequenz .api .common .v1alpha8 .pagination .pagination_params_pb2 import (
22+ PaginationParams as PBPaginationParamsAlpha8 ,
23+ )
24+ from typing_extensions import deprecated
1425
1526# pylint: enable=no-name-in-module
1627
1728
29+ @deprecated (
30+ "Params is deprecated, use PaginationParams instead." ,
31+ )
1832@dataclass (frozen = True , kw_only = True )
1933class Params :
2034 """Parameters for paginating list requests."""
@@ -26,7 +40,7 @@ class Params:
2640 """The token identifying a specific page of the list results."""
2741
2842 @classmethod
29- def from_proto (cls , pagination_params : PaginationParams ) -> Self :
43+ def from_proto (cls , pagination_params : PBPaginationParams ) -> Self :
3044 """Convert a protobuf Params to PaginationParams object.
3145
3246 Args:
@@ -39,18 +53,21 @@ def from_proto(cls, pagination_params: PaginationParams) -> Self:
3953 page_token = pagination_params .page_token ,
4054 )
4155
42- def to_proto (self ) -> PaginationParams :
56+ def to_proto (self ) -> PBPaginationParams :
4357 """Convert a Params object to protobuf PaginationParams.
4458
4559 Returns:
4660 Protobuf message corresponding to the Params object.
4761 """
48- return PaginationParams (
62+ return PBPaginationParams (
4963 page_size = self .page_size ,
5064 page_token = self .page_token ,
5165 )
5266
5367
68+ @deprecated (
69+ "Info is deprecated, use PaginationInfo instead." ,
70+ )
5471@dataclass (frozen = True , kw_only = True )
5572class Info :
5673 """Information about the pagination of a list request."""
@@ -62,7 +79,7 @@ class Info:
6279 """The token identifying the next page of results."""
6380
6481 @classmethod
65- def from_proto (cls , pagination_info : PaginationInfo ) -> Self :
82+ def from_proto (cls , pagination_info : PBPaginationInfo ) -> Self :
6683 """Convert a protobuf PBPaginationInfo to Info object.
6784
6885 Args:
@@ -75,13 +92,85 @@ def from_proto(cls, pagination_info: PaginationInfo) -> Self:
7592 next_page_token = pagination_info .next_page_token ,
7693 )
7794
78- def to_proto (self ) -> PaginationInfo :
95+ def to_proto (self ) -> PBPaginationInfo :
7996 """Convert a Info object to protobuf PBPaginationInfo.
8097
8198 Returns:
8299 Protobuf message corresponding to the Info object.
83100 """
84- return PaginationInfo (
101+ return PBPaginationInfo (
102+ total_items = self .total_items ,
103+ next_page_token = self .next_page_token ,
104+ )
105+
106+
107+ @dataclass (frozen = True , kw_only = True )
108+ class PaginationParams :
109+ """Parameters for paginating list requests."""
110+
111+ page_size : int
112+ """The maximum number of results to be returned per request."""
113+
114+ page_token : str
115+ """The token identifying a specific page of the list results."""
116+
117+ @classmethod
118+ def from_proto (cls , pagination_params : PBPaginationParamsAlpha8 ) -> Self :
119+ """Convert a protobuf PaginationParams to python PaginationParams object.
120+
121+ Args:
122+ pagination_params: Params to convert.
123+ Returns:
124+ Params object corresponding to the protobuf message.
125+ """
126+ return cls (
127+ page_size = pagination_params .page_size ,
128+ page_token = pagination_params .page_token ,
129+ )
130+
131+ def to_proto (self ) -> PBPaginationParamsAlpha8 :
132+ """Convert a Params object to protobuf PaginationParams.
133+
134+ Returns:
135+ Protobuf message corresponding to the Params object.
136+ """
137+ return PBPaginationParamsAlpha8 (
138+ page_size = self .page_size ,
139+ page_token = self .page_token ,
140+ )
141+
142+
143+ @dataclass (frozen = True , kw_only = True )
144+ class PaginationInfo :
145+ """Information about the pagination of a list request."""
146+
147+ total_items : int
148+ """The total number of items that match the request."""
149+
150+ next_page_token : str | None = None
151+ """The token identifying the next page of results."""
152+
153+ @classmethod
154+ def from_proto (cls , pagination_info : PBPaginationInfoAlpha8 ) -> Self :
155+ """Convert a protobuf PBPaginationInfo to Info object.
156+
157+ Args:
158+ pagination_info: Info to convert.
159+ Returns:
160+ Info object corresponding to the protobuf message.
161+ """
162+ return cls (
163+ total_items = pagination_info .total_items ,
164+ next_page_token = pagination_info .next_page_token ,
165+ )
166+
167+ def to_proto (self ) -> PBPaginationInfoAlpha8 :
168+ """Convert a Info object to protobuf PBPaginationInfo.
169+
170+ Returns:
171+ Protobuf message corresponding to the Info object.
172+ """
173+ return PBPaginationInfoAlpha8 (
85174 total_items = self .total_items ,
86175 next_page_token = self .next_page_token ,
87176 )
0 commit comments