use reqwest::header::{HeaderMap, HeaderValue};
use serde::Deserialize;
use crate::UsptoApiError;
#[derive(Debug, Deserialize)]
pub struct FileWrapperResponse {
pub count: u32,
#[serde(rename = "patentFileWrapperDataBag")]
pub patent_file_wrapper_data_bag: Vec<FileWrapperBag>,
}
impl FileWrapperResponse {
pub const fn is_empty(&self) -> bool {
self.count == 0
}
}
#[derive(Debug, Deserialize)]
pub struct FileWrapperBag {
#[serde(rename = "grantDocumentMetaData")]
pub grant_document_meta_data: Option<GrantDocMeta>,
}
#[derive(Debug, Deserialize)]
pub struct GrantDocMeta {
#[serde(rename = "fileLocationURI")]
pub file_location_uri: String,
}
pub fn construct_headers(api_key: &str) -> Result<HeaderMap, UsptoApiError> {
let mut headers = HeaderMap::new();
if api_key.is_empty() {
return Err(UsptoApiError::MissingApiKey);
}
headers.insert("X-API-KEY", HeaderValue::from_str(api_key)?);
Ok(headers)
}
pub fn construct_query_params(patent_number: &str) -> [(&str, String); 3] {
let q = format!("applicationMetaData.patentNumber:{patent_number}");
[
("q", q),
("pagination[offset]", "0".to_string()),
("pagination[limit]", "1".to_string()),
]
}