1use nil_core::city::{CitySearch, PublicCity};
5use nil_core::continent::Coord;
6use nil_core::error::Error as CoreError;
7use nil_core::ranking::score::Score;
8use nil_core::world::World;
9use nil_core::world::config::WorldId;
10use serde::{Deserialize, Serialize};
11
12#[derive(Clone, Debug, Deserialize, Serialize)]
13#[serde(rename_all = "camelCase")]
14pub struct GetCityRequest {
15 pub world: WorldId,
16 pub coord: Coord,
17}
18
19#[derive(Clone, Debug, Deserialize, Serialize)]
20#[serde(rename_all = "camelCase")]
21pub struct GetCityScoreRequest {
22 pub world: WorldId,
23 pub coord: Coord,
24}
25
26#[derive(Clone, Debug, Deserialize, Serialize)]
27#[serde(rename_all = "camelCase")]
28pub struct GetPublicCitiesRequest {
29 pub world: WorldId,
30 #[serde(default)]
31 pub coords: Vec<Coord>,
32 #[serde(default)]
33 pub score: bool,
34 #[serde(default)]
35 pub all: bool,
36}
37
38#[derive(Clone, Debug, Deserialize, Serialize)]
39#[serde(rename_all = "camelCase")]
40pub struct GetPublicCityRequest {
41 pub world: WorldId,
42 pub coord: Coord,
43 #[serde(default)]
44 pub score: bool,
45}
46
47#[derive(Clone, Debug, Deserialize, Serialize)]
48#[serde(rename_all = "camelCase")]
49pub struct GetPublicCityResponse {
50 pub city: PublicCity,
51 pub score: Option<Score>,
52}
53
54#[bon::bon]
55impl GetPublicCityResponse {
56 #[builder]
57 pub fn new(
58 #[builder(start_fn)] world: &World,
59 #[builder(start_fn)] coord: Coord,
60 #[builder(default)] score: bool,
61 ) -> Result<Self, CoreError> {
62 let city = world.city(coord)?;
63 let score = score
64 .then(|| city.score(&world.stats().infrastructure()))
65 .transpose()?;
66
67 Ok(Self { city: PublicCity::from(city), score })
68 }
69}
70
71#[derive(Clone, Debug, Deserialize, Serialize)]
72#[serde(rename_all = "camelCase")]
73pub struct RenameCityRequest {
74 pub world: WorldId,
75 pub coord: Coord,
76 pub name: String,
77}
78
79#[derive(Clone, Debug, Deserialize, Serialize)]
80#[serde(rename_all = "camelCase")]
81pub struct SearchCityRequest {
82 pub world: WorldId,
83 pub search: CitySearch,
84}
85
86#[derive(Clone, Debug, Deserialize, Serialize)]
87#[serde(rename_all = "camelCase")]
88pub struct SearchPublicCityRequest {
89 pub world: WorldId,
90 pub search: CitySearch,
91}