use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::Ident;

/// Resolves schema crate path (`armour-typ`, then `armour-core`, else `::armour_typ`).
pub fn schema_crate_path() -> TokenStream {
    use proc_macro_crate::{FoundCrate, crate_name};
    for name in ["armour-typ", "armour-core"] {
        if let Ok(found) = crate_name(name) {
            return match found {
                FoundCrate::Itself => quote!(crate),
                FoundCrate::Name(n) => {
                    let id = Ident::new(&n, Span::call_site());
                    quote!(::#id)
                }
            };
        }
    }
    quote!(::armour_typ)
}
