use serde::{Deserialize, Serialize};
use crate::Map;
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct SecurityRequirement(pub Map<Vec<String>>);
impl SecurityRequirement {
#[must_use]
pub fn anonymous() -> Self {
Self(Map::new())
}
pub fn scheme(name: impl Into<String>) -> Self {
let mut map = Map::new();
map.insert(name.into(), Vec::new());
Self(map)
}
pub fn scoped(
name: impl Into<String>,
scopes: impl IntoIterator<Item = impl Into<String>>,
) -> Self {
let mut map = Map::new();
map.insert(name.into(), scopes.into_iter().map(Into::into).collect());
Self(map)
}
#[must_use]
pub fn and(
mut self,
name: impl Into<String>,
scopes: impl IntoIterator<Item = impl Into<String>>,
) -> Self {
self.0
.insert(name.into(), scopes.into_iter().map(Into::into).collect());
self
}
#[must_use]
pub fn is_anonymous(&self) -> bool {
self.0.is_empty()
}
}