use std::vec;
use aranya_daemon_api as api;
use aranya_id::custom_id;
use aranya_policy_text::Text;
use crate::{
client::DeviceId,
util::{impl_vec_into_iter_wrapper, ApiConv as _, ApiId},
};
custom_id! {
pub struct LabelId;
}
impl ApiId<api::LabelId> for LabelId {}
#[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[non_exhaustive]
pub struct Label {
pub id: LabelId,
pub name: Text,
pub author_id: DeviceId,
}
impl Label {
pub(crate) fn from_api(v: api::Label) -> Self {
Self {
id: LabelId::from_api(v.id),
name: v.name,
author_id: DeviceId::from_api(v.author_id),
}
}
}
#[derive(Clone, Debug)]
pub struct Labels {
pub(super) labels: Box<[Label]>,
}
impl Labels {
pub fn iter(&self) -> impl Iterator<Item = &Label> {
self.labels.iter()
}
#[doc(hidden)]
pub fn __data(&self) -> &[Label] {
&self.labels
}
}
impl IntoIterator for Labels {
type Item = Label;
type IntoIter = IntoIterLabels;
fn into_iter(self) -> Self::IntoIter {
IntoIterLabels(self.labels.into_vec().into_iter())
}
}
#[derive(Clone, Debug)]
pub struct IntoIterLabels(vec::IntoIter<Label>);
impl_vec_into_iter_wrapper!(IntoIterLabels for Label);