use quote::{quote, ToTokens};

use super::document::DocumentItemAttributes;

#[derive(Clone)]
pub struct StructType {
    pub inner: syn::ItemStruct,
}

impl syn::parse::Parse for StructType {
    fn parse(input: syn::parse::ParseStream<'_>) -> syn::Result<Self> {
        let mut inner: syn::ItemStruct = input.parse()?;
        inner.vis = syn::Visibility::Public(syn::token::Pub(input.span()));
        Ok(Self { inner })
    }
}

impl DocumentItemAttributes for StructType {
    fn extend_attributes<I: IntoIterator<Item = syn::Attribute>>(&mut self, attrs: I) {
        self.inner.attrs.extend(attrs);
    }
}

impl ToTokens for StructType {
    fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
        let Self { inner } = self;
        tokens.extend(quote!(#inner));
    }
}
