use serde::ser::Serialize;
use serde_json::Value;

use api::rpc::Error;

pub fn parse_error() -> Error {
    Error {
        message: "parse error".to_owned(),
        code: -32700,
        data: None,
    }
}

pub fn invalid_request() -> Error {
    Error {
        message: "invalid request".to_owned(),
        code: -32600,
        data: None,
    }
}

pub fn invalid_version() -> Error 


pub fn method_not_found() -> Error {
    Error {
        message: "method not found".to_owned(),
        code: -32601,
        data: None,
    }
}

// pub fn invalid_params(params: Value) -> Error {
//     Error {
//         code: -32602,
//         message: "invalid params".to_owned(),
//         data: params,
//     }
// }

pub fn invalid_param(param: &str, reason: &str) -> Error {
    Error {
        code: -32602,
        message: "invalid params".to_owned(),
        data: Some(json!([{ param: reason }])),
    }
}

pub fn internal_error() -> Error {
    Error {
        message: "internal error".to_owned(),
        code: -32603,
        data: None,
    }
}

pub fn scope_not_found() -> Error {
    Error {
        message: "scope_not_found".to_owned(),
        code: -32000,
        data: None,
    }
}

{
    Error {
        code: -32600,
        message: "unsupported JSON-RPC protocol version".to_owned(),
        data: None,
    }
}