use crate::types::{Bbox, Lac, Mcc, Mnc, Radio};
#[derive(Debug, Clone)]
pub struct AreaQuery {
pub bbox: Bbox,
pub mcc: Option<Mcc>,
pub mnc: Option<Mnc>,
pub lac: Option<Lac>,
pub radio: Option<Radio>,
}
impl AreaQuery {
pub fn new(bbox: Bbox) -> Self {
Self { bbox, mcc: None, mnc: None, lac: None, radio: None }
}
pub fn mcc(mut self, mcc: Mcc) -> Self {
self.mcc = Some(mcc);
self
}
pub fn mnc(mut self, mnc: Mnc) -> Self {
self.mnc = Some(mnc);
self
}
pub fn lac(mut self, lac: Lac) -> Self {
self.lac = Some(lac);
self
}
pub fn radio(mut self, radio: Radio) -> Self {
self.radio = Some(radio);
self
}
}
#[derive(Debug, Clone)]
pub struct GetCellsInAreaParams {
pub query: AreaQuery,
pub limit: Option<u32>,
pub offset: Option<u32>,
}
impl GetCellsInAreaParams {
pub fn new(query: AreaQuery) -> Self {
Self { query, limit: None, offset: None }
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
pub fn offset(mut self, offset: u32) -> Self {
self.offset = Some(offset);
self
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::types::Bbox;
fn bbox() -> Bbox {
Bbox::new(0.0, 0.0, 1.0, 1.0).unwrap()
}
#[test]
fn area_query_setters_cover_all_fields() {
let q = AreaQuery::new(bbox()).mcc(250).mnc(1).lac(7800).radio(crate::types::Radio::Lte);
assert_eq!(q.mcc, Some(250));
assert_eq!(q.mnc, Some(1));
assert_eq!(q.lac, Some(7800));
assert_eq!(q.radio, Some(crate::types::Radio::Lte));
}
#[test]
fn area_query_last_setter_wins() {
let q = AreaQuery::new(bbox()).mcc(1).mcc(2);
assert_eq!(q.mcc, Some(2));
}
#[test]
fn get_cells_in_area_params_pagination() {
let p = GetCellsInAreaParams::new(AreaQuery::new(bbox()))
.limit(50)
.offset(100);
assert_eq!(p.limit, Some(50));
assert_eq!(p.offset, Some(100));
}
}