bpi_rs/web_widget/
params.rs1use crate::video::video_zone_v2::VideoPartitionV2;
2use crate::{BpiError, BpiResult};
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub struct WebWidgetHeaderPageParams {
7 resource_id: u32,
8}
9
10impl Default for WebWidgetHeaderPageParams {
11 fn default() -> Self {
12 Self { resource_id: 142 }
13 }
14}
15
16impl WebWidgetHeaderPageParams {
17 pub fn new() -> Self {
18 Self::default()
19 }
20
21 pub fn with_resource_id(mut self, resource_id: u32) -> BpiResult<Self> {
22 if resource_id == 0 {
23 return Err(BpiError::invalid_parameter(
24 "resource_id",
25 "value must be non-zero",
26 ));
27 }
28
29 self.resource_id = resource_id;
30 Ok(self)
31 }
32
33 pub(crate) fn query_pairs(&self) -> [(&'static str, String); 1] {
34 [("resource_id", self.resource_id.to_string())]
35 }
36}
37
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40pub struct WebWidgetRegionBannerParams {
41 region_id: u32,
42}
43
44impl WebWidgetRegionBannerParams {
45 pub fn new(region_id: VideoPartitionV2) -> Self {
46 Self {
47 region_id: region_id.tid(),
48 }
49 }
50
51 pub(crate) fn query_pairs(&self) -> [(&'static str, String); 1] {
52 [("region_id", self.region_id.to_string())]
53 }
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59 use crate::video::video_zone_v2::Douga;
60
61 #[test]
62 fn header_page_params_serializes_default_resource() {
63 let params = WebWidgetHeaderPageParams::new();
64
65 assert_eq!(params.query_pairs(), [("resource_id", "142".to_string())]);
66 }
67
68 #[test]
69 fn header_page_params_serializes_custom_resource() -> BpiResult<()> {
70 let params = WebWidgetHeaderPageParams::new().with_resource_id(143)?;
71
72 assert_eq!(params.query_pairs(), [("resource_id", "143".to_string())]);
73 Ok(())
74 }
75
76 #[test]
77 fn header_page_params_rejects_zero_resource() {
78 let err = WebWidgetHeaderPageParams::new()
79 .with_resource_id(0)
80 .unwrap_err();
81
82 assert!(matches!(
83 err,
84 BpiError::InvalidParameter {
85 field: "resource_id",
86 ..
87 }
88 ));
89 }
90
91 #[test]
92 fn region_banner_params_serializes_partition_id() {
93 let partition = VideoPartitionV2::Douga(Douga::Douga);
94 let expected_tid = partition.tid().to_string();
95 let params = WebWidgetRegionBannerParams::new(partition);
96
97 assert_eq!(params.query_pairs(), [("region_id", expected_tid)]);
98 }
99}