1"""Routes of the Mount API."""
2
3from typing import TYPE_CHECKING
4
5from wow._async._resource import AsyncResource
6from wow.models.mount import Mount, MountIndex, MountSearchData
7from wow.search import MAX_PAGE_SIZE
8
9if TYPE_CHECKING:
10 from collections.abc import AsyncIterator, Mapping, Sequence
11
12 from wow.models._common import SearchPage, SearchResult
13 from wow.search import FilterValue
14
15__all__ = ["AsyncMounts"]
16
17
[docs]
18class AsyncMounts(AsyncResource):
19 """``client.mounts``: mounts."""
20
21 __slots__ = ()
22
[docs]
23 async def index(self) -> MountIndex:
24 """List every mount."""
25 return await self._get("static", "/data/wow/mount/index", MountIndex)
26
[docs]
27 async def get(self, mount_id: int) -> Mount:
28 """Get one mount by id."""
29 return await self._get("static", f"/data/wow/mount/{mount_id}", Mount)
30
[docs]
31 async def search(
32 self,
33 *,
34 name: str | None = None,
35 filters: Mapping[str, FilterValue] | None = None,
36 order_by: str | Sequence[str] | None = None,
37 page: int = 1,
38 page_size: int = 100,
39 ) -> SearchPage[MountSearchData]:
40 """Search mounts.
41
42 Args:
43 name: Match this text in the client's locale.
44 filters: Field filters, such as ``{"faction.type": "ALLIANCE"}``.
45 order_by: Field name(s) to sort by, each optionally suffixed ``:desc``.
46 page: The page to fetch, starting at 1.
47 page_size: Results per page.
48 """
49 return await self._search(
50 "static",
51 "mount",
52 MountSearchData,
53 filters=self._localized_name(name, filters),
54 order_by=order_by,
55 page=page,
56 page_size=page_size,
57 )
58
[docs]
59 def search_all(
60 self,
61 *,
62 name: str | None = None,
63 filters: Mapping[str, FilterValue] | None = None,
64 order_by: str | Sequence[str] | None = None,
65 page_size: int = MAX_PAGE_SIZE,
66 ) -> AsyncIterator[SearchResult[MountSearchData]]:
67 """Iterate over every result across pages (Battle.net stops at 1,000).
68
69 Args:
70 name: Match this text in the client's locale.
71 filters: Field filters, such as ``{"faction.type": "ALLIANCE"}``.
72 order_by: Field name(s) to sort by, each optionally suffixed ``:desc``.
73 page_size: Results per page.
74 """
75 return self._search_all(
76 "static",
77 "mount",
78 MountSearchData,
79 filters=self._localized_name(name, filters),
80 order_by=order_by,
81 page_size=page_size,
82 )