// darling 0.23.0 emits `continue;` expressions in the code generated by its
// `FromAttributes` / `FromDeriveInput` derives, which trip
// `clippy::needless_continue`. The lint can only be suppressed at the use
// site, not inside the macro expansion.
//
// Fixed upstream in <https://github.com/TedDriggs/darling/issues/399>; remove
// this allow once the next darling release ships.
#![allow(clippy::needless_continue)]

mod common;
mod utils;

#[cfg(feature = "config")]
mod config;
#[cfg(feature = "config")]
mod config_enum;
#[cfg(feature = "schema")]
mod schematic;

use common::Macro;
use proc_macro::TokenStream;
use quote::quote;
use syn::{DeriveInput, parse_macro_input};

// #[derive(Config)]
#[cfg(feature = "config")]
#[proc_macro_derive(Config, attributes(config, setting))]
pub fn config(item: TokenStream) -> TokenStream {
    let input: DeriveInput = parse_macro_input!(item);
    let output = config::ConfigMacro(Macro::from(&input));

    quote! { #output }.into()
}

// #[derive(ConfigEnum)]
#[cfg(feature = "config")]
#[proc_macro_derive(ConfigEnum, attributes(config, variant))]
pub fn config_enum(item: TokenStream) -> TokenStream {
    config_enum::macro_impl(item)
}

// #[derive(Schematic)]
#[cfg(feature = "schema")]
#[proc_macro_derive(Schematic, attributes(schematic, schema))]
pub fn schematic(item: TokenStream) -> TokenStream {
    let input: DeriveInput = parse_macro_input!(item);
    let output = schematic::SchematicMacro(Macro::from(&input));

    quote! { #output }.into()
}
