use proc_macro2::TokenStream;
use syn::{ExprLit, Token, spanned::Spanned};


pub(crate) fn custom_base_path(input: CustomPath) -> syn::Result<TokenStream> {
    let CustomPath { base_path, relative_path } = input;

    let path = super::parse_path_from_expr_lit(&base_path)
        .and_then(|(base_path, _)| super::parse_relative_path(base_path, relative_path.as_ref()))?;

    super::quote_path_buf(path, relative_path.span())
}


pub(crate) struct CustomPath {
    pub(crate) base_path: ExprLit,
    pub(crate) relative_path: Option<ExprLit>,
}

impl syn::parse::Parse for CustomPath {
    fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {

        let base = input.parse()?;
        let relative = if input.is_empty() {
            None
        } else {
            input.parse::<Token![,]>()?;
            Some(input.parse()?)
        };

        Ok(Self {
            base_path: base,
            relative_path: relative,
        })
    }
}
