rglw_api_codegen 0.0.1

Rustyglware websocket api.
Documentation
use proc_macro2::TokenStream;
use quote::{quote};
use rglw::codegen_utils::derive_attributes::DeriveAttributes;
use syn::DeriveInput;

use crate::derives::injectable::implementation as injectable_implementation;

pub fn implementation(input: DeriveInput) -> TokenStream {

    let injectable_expanded = injectable_implementation(input.clone());
    let ident = input.ident;

    let attributes = DeriveAttributes::new(input.attrs);

    let service_type_attribute = attributes.find_by_name("service_type");

    let mut service_type: String = "Default".to_string();

    if service_type_attribute.is_some() {
        let service_type_attribute = attributes.find_list_attribute_arguments("service_type").unwrap();
        service_type = service_type_attribute.to_string();
    }

    let expanded = match service_type.as_str() {
        "Default" => {
            quote! {
                #injectable_expanded
                #[async_trait::async_trait]
                impl Service for #ident {
                    async fn setup(&self) -> Result<(), RglwApiError> {
                        Ok(())
                    }
                }
            }
        },
        "Custom" => {
            quote! {
                #injectable_expanded
            }
        }
        _=> {
            panic!("Unsupported service type value");
        }
    };

    expanded
}