fiberplane_models/providers/schema/fields/
integer_field.rs1#[cfg(feature = "fp-bindgen")]
2use fp_bindgen::prelude::Serializable;
3use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
7#[cfg_attr(
8 feature = "fp-bindgen",
9 derive(Serializable),
10 fp(rust_module = "fiberplane_models::providers")
11)]
12#[non_exhaustive]
13#[serde(rename_all = "camelCase")]
14pub struct IntegerField {
15 pub name: String,
18
19 pub label: String,
21
22 #[serde(default, skip_serializing_if = "Option::is_none")]
24 pub max: Option<i32>,
25
26 #[serde(default, skip_serializing_if = "Option::is_none")]
28 pub min: Option<i32>,
29
30 pub placeholder: String,
32
33 pub required: bool,
35
36 #[serde(default, skip_serializing_if = "Option::is_none")]
40 pub step: Option<i32>,
41}
42
43impl IntegerField {
44 pub fn new() -> Self {
46 Default::default()
47 }
48
49 pub fn required(self) -> Self {
51 Self {
52 required: true,
53 ..self
54 }
55 }
56
57 pub fn with_bounds(self, min: i32, max: i32) -> Self {
59 Self {
60 max: Some(max),
61 min: Some(min),
62 ..self
63 }
64 }
65
66 pub fn with_label(self, label: impl Into<String>) -> Self {
67 Self {
68 label: label.into(),
69 ..self
70 }
71 }
72
73 pub fn with_max(self, max: i32) -> Self {
74 Self {
75 max: Some(max),
76 ..self
77 }
78 }
79
80 pub fn with_min(self, min: i32) -> Self {
81 Self {
82 min: Some(min),
83 ..self
84 }
85 }
86
87 pub fn with_name(self, name: impl Into<String>) -> Self {
88 Self {
89 name: name.into(),
90 ..self
91 }
92 }
93
94 pub fn with_step(self, step: i32) -> Self {
95 Self {
96 step: Some(step),
97 ..self
98 }
99 }
100}