use std::future;
use std::sync::Arc;

use log::info;
use serde::{Deserialize, Serialize};
use tower_lsp::jsonrpc::Result;
use crate::server::Backend;


#[derive(Clone)]
pub struct CustomRequest;

impl <'a>tower_lsp::jsonrpc::Method<&'a Arc<Backend>, (), Result<i32>> for CustomRequest {
    type Future = future::Ready<Result<i32>>;

    fn invoke(&self, _server: &'a Arc<Backend>, _params: ()) -> Self::Future {
        future::ready(custom_request())
    }
}

pub fn custom_request() -> Result<i32> {
    Ok(123)
}

#[derive(Deserialize, Serialize, Debug)]
pub struct CustomParamRequestParams {
    param: String,
}

#[derive(Clone)]
pub struct CustomParamRequest;

impl <'a>tower_lsp::jsonrpc::Method<&'a Arc<Backend>, (CustomParamRequestParams, ), Result<i32>> for CustomParamRequest {
    type Future = future::Ready<Result<i32>>;

    fn invoke(&self, _server: &'a Arc<Backend>, _params: (CustomParamRequestParams, )) -> Self::Future {
        future::ready(custom_param_request(_params.0.param))
    }
}

pub fn custom_param_request(param: String) -> Result<i32> {
    info!("receive param: {:?}", param);
    Ok(123)
}