extern crate proc_macro;

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

/// Derive macro to generate LLM-ready JSON schema from any struct
/// Works with serde::Serialize and schemars::JsonSchema
///
/// # Example
/// ```ignore
/// use schemars::JsonSchema;
/// use schemabound_schema::LlmSchema;
/// use serde::{Deserialize, Serialize};
///
/// #[derive(Serialize, Deserialize, JsonSchema, LlmSchema)]
/// pub struct Organization {
///     pub id: String,
///     pub name: String,
/// }
///
/// let schema = Organization::llm_schema();
/// ```
#[proc_macro_derive(LlmSchema)]
pub fn derive_llm_schema(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as DeriveInput);
    let name = &input.ident;

    let expanded = quote! {
        impl #name {
            /// Generate LLM-ready JSON schema for tool calling (OpenAI, Anthropic, etc.)
            ///
            /// Returns a schemars::schema::RootSchema that represents this struct
            /// as a JSON Schema, suitable for use as a function parameter schema
            /// in LLM function calling interfaces.
            pub fn llm_schema() -> schemars::schema::RootSchema {
                schemars::schema_for!(#name)
            }
        }
    };

    TokenStream::from(expanded)
}
